What I'm going to do is extract the name of the Test_case and the duration of the test_case (in seconds): Here's a sample meta-data
Start| 20140618 root (6033) | TPI 1.4 | 14:53:52 10050943579848 0 | Start| 20814 SunOS 5.11 11.2 i86pc tcx4440-01 | stf_env| Stc_name = Os-zones | stf_env| Stc_version = 2.10.0 | stf_env| Stc_os_version = 5.11 | stf_env| Stf_execute_mode = Ipkg:amd64 | stf_env| CWD =/opt/stc/suites/os/zones/tests/os/functional | Test_case_start| 20858 Tests/os/functional/setup | 14:53:52 10051107110387 0 |stdout| Stdout| 14:53:53 success:zone_is_running zone2stdout| Zone ' Zone2 ' is runningstdout| Stdout| 14:53:53 success:zone_is_running zone1stdout| Zone ' Zone1 ' is runningstdout| 14:53:53 zones ' Zone2 zone1 ' is runningtest_case_end| 20858 Tests/os/functional/setup | PASS | 14:53:53 10052165298138 0 |
The result I want to get is:
Tests/os/functional/setup 1
Because my metadata is relatively small (not more than 20MB, so I chose to use vector), the source code is as follows:
#include <iostream> #include <vector> #include <string> #include <fstream> #include <cstdlib >using namespace std;/** There is not split function, you should add one by yourself */vector<string> split (con St string &str, String pattern) {string:: Size_type pos; Vector <string> result; int size = Str.size (); int i = 0; for (i = 0; i < size; i++) {pos = Str.find (pattern, i); if (pos < size) {string subStr = Str.substr (i, pos-i);//substr (beginposition, length) cout<< "i =" <<i<< ", pos-1 =" <<pos-1<<endl; Cout<<str.substr (i, pos-i) <<endl; Result.push_back (SUBSTR); i = pos + pattern.size ()-1; cout<<substr<<endl; cout<< "i=" <<i<<endl; }} return result; /**duration TimE = endtime-starttime*eg:duration time = 1:10:08-23:08:08 = (8 * 3600 + +)-(* 3600 + 8 * + 7) */in T Getdurationtime (String startTime, String endTime) {vector<string> starttimevector;vector<string> Endtimevector;int starttimeseconds = 0;int endtimeseconds = 0;starttime = starttime+ ":";//1:10:08, if we do not add ":", We can not get EndTime = EndTime + ":"; endtimevector = Split (EndTime, ":"); starttimevector = Split (StartTime, ":"); star Ttimeseconds = Atoi (Starttimevector[0].c_str ()) * 3600 + atoi (STARTTIMEVECTOR[1].C_STR ()) * + atoi (starttimevector[2] . C_STR ()); endtimeseconds = Atoi (Endtimevector[0].c_str ()) * 3600 + atoi (ENDTIMEVECTOR[1].C_STR ()) * + atoi ( Endtimevector[2].c_str ()); if (Endtimeseconds < starttimeseconds) {endtimeseconds = endtimeseconds + 24 * 3600;} cout<< "Endtimeseconds:" <<endtimeseconds << "starttimeseconds:" <<startTimeSeconds< <endl;//cout<<endtimeseconds-starttimeseconds<<endl;reTurn endtimeseconds-starttimeseconds; }int Main () {vector< pair<string, int> > Casedurationvec; String journalinput = "Journal.base"; String journaloutput = "Journal.base.out"; Ifstream infile (Journalinput.c_str ()); Ofstream outfile (Journaloutput.c_str ()); string buffer; Const string Case_start = "Test_case_start"; Const string case_end = "Test_case_end"; int i = 0; Vector<string> Resultvec; String casestarttime = ""; String caseendtime = ""; while (Getline (infile, buffer)) {if (Buffer.find (case_start)! = Buffer.npos) {Resultvec = SPL It (buffer, ""); Casestarttime = resultvec[4]; } if (Buffer.find (case_end)! = Buffer.npos) {Resultvec = split (buffer, ""); Caseendtime = resultvec[6]; Casedurationvec.push_back (make_pair<string, int> (resultvec[2], Getdurationtime (caseStartTime, caseendtime))); cout<< "There is" <<i++<< "cases" <<endl; }} vector< pair<string, int> >:: Iterator iter; for (iter = Casedurationvec.begin (); ITER! = Casedurationvec.end (); iter++) {OUTFILE<<ITER->FIRST<&L t; "" <<iter->second<<endl; } infile.close (); Outfile.close (); System ("pause"); return 1;}
Implementation of C + + for collecting meta data