From 55020401d9139f318db713582e971516c09776bb Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Fri, 25 Aug 2017 18:28:09 -0700 Subject: [PATCH 01/29] Fix a few simple leaks inside twtest; fix some file permissions that got set wrong in last commit --- src/core/displayencoder.cpp | 0 src/core/hashtable.h | 0 src/twparser/yylex.cpp | 0 src/twparser/yyparse.cpp | 0 src/twtest/crytpo_t.cpp | 2 ++ src/twtest/fspropdisplayer_t.cpp | 2 ++ src/twtest/keyfile_t.cpp | 3 ++- src/twtest/refcountobj_t.cpp | 0 8 files changed, 6 insertions(+), 1 deletion(-) mode change 100755 => 100644 src/core/displayencoder.cpp mode change 100755 => 100644 src/core/hashtable.h mode change 100755 => 100644 src/twparser/yylex.cpp mode change 100755 => 100644 src/twparser/yyparse.cpp mode change 100755 => 100644 src/twtest/refcountobj_t.cpp diff --git a/src/core/displayencoder.cpp b/src/core/displayencoder.cpp old mode 100755 new mode 100644 diff --git a/src/core/hashtable.h b/src/core/hashtable.h old mode 100755 new mode 100644 diff --git a/src/twparser/yylex.cpp b/src/twparser/yylex.cpp old mode 100755 new mode 100644 diff --git a/src/twparser/yyparse.cpp b/src/twparser/yyparse.cpp old mode 100755 new mode 100644 diff --git a/src/twtest/crytpo_t.cpp b/src/twtest/crytpo_t.cpp index cf4c565..5d83447 100644 --- a/src/twtest/crytpo_t.cpp +++ b/src/twtest/crytpo_t.cpp @@ -407,6 +407,8 @@ void TestCrypto() delete pPublic; delete pPrivate; + delete pPublic2; + delete pPrivate2; } } diff --git a/src/twtest/fspropdisplayer_t.cpp b/src/twtest/fspropdisplayer_t.cpp index 770fdf6..a654df0 100644 --- a/src/twtest/fspropdisplayer_t.cpp +++ b/src/twtest/fspropdisplayer_t.cpp @@ -127,6 +127,8 @@ void cTestFSPropDisplayer::Test() d.TraceDebug("\n"); } + delete pPD; + delete pPDNew; return; } diff --git a/src/twtest/keyfile_t.cpp b/src/twtest/keyfile_t.cpp index 4570363..656dc05 100644 --- a/src/twtest/keyfile_t.cpp +++ b/src/twtest/keyfile_t.cpp @@ -107,8 +107,9 @@ void TestKeyFile() elGamal.SetVerifying(keyfile2.GetPublicKey()); elGamal.ProcessBlock(ciphertext, recovered_text); - + TEST(memcmp(recovered_text, plaintext, elGamal.GetBlockSizePlain()) == 0); + delete [] pMem; } // save to and read from disk diff --git a/src/twtest/refcountobj_t.cpp b/src/twtest/refcountobj_t.cpp old mode 100755 new mode 100644 From f4263cf2b8b2f9a7fe847e838288625d2fe3859c Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Fri, 25 Aug 2017 19:00:39 -0700 Subject: [PATCH 02/29] Comment out some #line directives in twparser, since they confuse gcov --- src/twparser/yylex.cpp | 88 ++++++++++++++++++++-------------------- src/twparser/yylex.h | 2 +- src/twparser/yyparse.cpp | 84 +++++++++++++++++++------------------- 3 files changed, 87 insertions(+), 87 deletions(-) diff --git a/src/twparser/yylex.cpp b/src/twparser/yylex.cpp index 7b6cee5..6ce9855 100644 --- a/src/twparser/yylex.cpp +++ b/src/twparser/yylex.cpp @@ -478,7 +478,7 @@ static int yy_base[] = { }; -#line 152 "..\\..\\mkslexyacc\\etc\\yylex.cpp" +// #line 152 "..\\..\\mkslexyacc\\etc\\yylex.cpp" // MKS LEX prototype scanner code // Copyright 1991 by Mortice Kern Systems Inc. @@ -505,7 +505,7 @@ const int MIN_NUM_STATES = 20; #define REJECT goto yy_reject #define yymore() goto yy_more -#line 10 "tokens.l" +// #line 10 "tokens.l" #include "stdtwparser.h" @@ -563,7 +563,7 @@ std::string FormatSyntaxError( char ch, const char* pszAdditionalMsg = NULL ) // saves typing #define TRACE_RETURN(x) lextrace(_T(#x)); return x -#line 178 "..\\..\\mkslexyacc\\etc\\yylex.cpp" +// #line 178 "..\\..\\mkslexyacc\\etc\\yylex.cpp" // Constructor for yy_scan. Set up tables @@ -762,7 +762,7 @@ yy_scan::yylex() int yyoldi, yyoleng; /* base i, yyleng before look-ahead */ int yyeof; /* 1 if eof has already been read */ -#line 375 "..\\..\\mkslexyacc\\etc\\yylex.cpp" +// #line 375 "..\\..\\mkslexyacc\\etc\\yylex.cpp" #ifdef YYEXIT @@ -876,43 +876,43 @@ yy_scan::yylex() YY_USER(); switch (yy_la_act[yyfmin] & 0777) { case 0: -#line 109 "tokens.l" +// #line 109 "tokens.l" { BEGIN( globals ); } break; case 1: -#line 114 "tokens.l" +// #line 114 "tokens.l" { BEGIN(INITIAL); return TWP_SECTION; } break; case 2: -#line 119 "tokens.l" +// #line 119 "tokens.l" { TRACE_RETURN(TWP_ECHO); } break; case 3: -#line 122 "tokens.l" +// #line 122 "tokens.l" { lextrace(_T("eating spaces...")); /* eat spaces */ } break; case 4: -#line 125 "tokens.l" +// #line 125 "tokens.l" { cParserHelper::IncrementLineNumber(); lextrace(_T("eating line continuation...")); /* eat line continuations */ } break; case 5: -#line 129 "tokens.l" +// #line 129 "tokens.l" { lextrace(_T("eating comment...")); } break; case 6: -#line 138 "tokens.l" +// #line 138 "tokens.l" { // we must make copy of string, otherwise another lexeme will clobber it cDebug d("\t\t\t\tlexer::string"); @@ -931,7 +931,7 @@ yy_scan::yylex() } break; case 7: -#line 155 "tokens.l" +// #line 155 "tokens.l" { // we must make copy of string, otherwise another lexeme will clobber it cDebug d("\t\t\t\tlexer::qstring"); @@ -960,19 +960,19 @@ yy_scan::yylex() } break; case 8: -#line 182 "tokens.l" +// #line 182 "tokens.l" { TRACE_RETURN(TWP_SEMICOLON); } break; case 9: -#line 183 "tokens.l" +// #line 183 "tokens.l" { TRACE_RETURN(TWP_EQUALS); } break; case 10: -#line 185 "tokens.l" +// #line 185 "tokens.l" { cParserHelper::IncrementLineNumber(); } break; case 11: -#line 186 "tokens.l" +// #line 186 "tokens.l" { std::string strError; strError = FormatSyntaxError( yytext[0], "The global section only accepts statements of the form:\n variable = value;\n" ); @@ -981,102 +981,102 @@ yy_scan::yylex() } /* catches anything that cannot be deemed a variable definition and exits. */ break; case 12: -#line 196 "tokens.l" +// #line 196 "tokens.l" { lextrace(_T("eating spaces...")); /* eat spaces */ } break; case 13: -#line 200 "tokens.l" +// #line 200 "tokens.l" { cParserHelper::IncrementLineNumber(); lextrace(_T("eating line continuation...")); /* eat line continuations */ } break; case 14: -#line 205 "tokens.l" +// #line 205 "tokens.l" { lextrace(_T("eating comment...")); } break; case 15: -#line 209 "tokens.l" +// #line 209 "tokens.l" { TRACE_RETURN(TWP_LBRACE); } break; case 16: -#line 210 "tokens.l" +// #line 210 "tokens.l" { TRACE_RETURN(TWP_RBRACE); } break; case 17: -#line 213 "tokens.l" +// #line 213 "tokens.l" { TRACE_RETURN(TWP_BANG); } break; case 18: -#line 215 "tokens.l" +// #line 215 "tokens.l" { TRACE_RETURN(TWP_RARROW); } break; case 19: -#line 216 "tokens.l" +// #line 216 "tokens.l" { TRACE_RETURN(TWP_EQUALS); } break; case 20: -#line 218 "tokens.l" +// #line 218 "tokens.l" { TRACE_RETURN(TWP_SEMICOLON); } break; case 21: -#line 219 "tokens.l" +// #line 219 "tokens.l" { TRACE_RETURN(TWP_LPAREN); } break; case 22: -#line 220 "tokens.l" +// #line 220 "tokens.l" { TRACE_RETURN(TWP_RPAREN); } break; case 23: -#line 221 "tokens.l" +// #line 221 "tokens.l" { TRACE_RETURN(TWP_COMMA); } break; case 24: -#line 222 "tokens.l" +// #line 222 "tokens.l" { TRACE_RETURN(TWP_PIPE); } break; case 25: -#line 226 "tokens.l" +// #line 226 "tokens.l" { TRACE_RETURN(TWP_DOLLAR); } break; case 26: -#line 227 "tokens.l" +// #line 227 "tokens.l" { TRACE_RETURN(TWP_OROR); } break; case 27: -#line 230 "tokens.l" +// #line 230 "tokens.l" { TRACE_RETURN(TWP_SECTION); } break; case 28: -#line 231 "tokens.l" +// #line 231 "tokens.l" { TRACE_RETURN(TWP_IFHOST); } break; case 29: -#line 232 "tokens.l" +// #line 232 "tokens.l" { TRACE_RETURN(TWP_ELSE); } break; case 30: -#line 233 "tokens.l" +// #line 233 "tokens.l" { TRACE_RETURN(TWP_ENDIF); } break; case 31: -#line 234 "tokens.l" +// #line 234 "tokens.l" { TRACE_RETURN(TWP_ERROR); } break; case 32: -#line 235 "tokens.l" +// #line 235 "tokens.l" { TRACE_RETURN(TWP_ECHO); } break; case 33: -#line 236 "tokens.l" +// #line 236 "tokens.l" { lextrace( _T( "@@end" ) ); return 0; } /* logical end of file */ break; case 34: -#line 239 "tokens.l" +// #line 239 "tokens.l" { // we must make copy of string, otherwise another lexeme will clobber it cDebug d("\t\t\t\tlexer::string"); @@ -1095,7 +1095,7 @@ yy_scan::yylex() } break; case 35: -#line 256 "tokens.l" +// #line 256 "tokens.l" { // we must make copy of string, otherwise another lexeme will clobber it cDebug d("\t\t\t\tlexer::qstring"); @@ -1134,11 +1134,11 @@ yy_scan::yylex() } break; case 36: -#line 309 "tokens.l" +// #line 309 "tokens.l" { cParserHelper::IncrementLineNumber(); } break; case 37: -#line 310 "tokens.l" +// #line 310 "tokens.l" { std::string strError; strError = FormatSyntaxError( yytext[0] ); @@ -1147,7 +1147,7 @@ yy_scan::yylex() } /* catches anything else that's not in here and quits */ break; -#line 487 "..\\..\\mkslexyacc\\etc\\yylex.cpp" +// #line 487 "..\\..\\mkslexyacc\\etc\\yylex.cpp" } YY_SCANNER(); @@ -1231,7 +1231,7 @@ yy_scan::unput(int c) return c; } -#line 321 "tokens.l" +// #line 321 "tokens.l" diff --git a/src/twparser/yylex.h b/src/twparser/yylex.h index 82f1600..10a3b3f 100644 --- a/src/twparser/yylex.h +++ b/src/twparser/yylex.h @@ -38,7 +38,7 @@ #endif #define YYNEWLINE 10 -#line 1 "..\\..\\mkslexyacc\\etc\\yylex.cpp" +//#line 1 "..\\..\\mkslexyacc\\etc\\yylex.cpp" // MKS LEX prototype scanner header // Copyright 1991 by Mortice Kern Systems Inc. // All rights reserved. diff --git a/src/twparser/yyparse.cpp b/src/twparser/yyparse.cpp index 92fc06b..dfcb71c 100644 --- a/src/twparser/yyparse.cpp +++ b/src/twparser/yyparse.cpp @@ -30,7 +30,7 @@ // info@tripwire.org or www.tripwire.org. // /* ..\. -LC -o ..\twparser\yyparse.cpp -P ..\..\mkslexyacc\etc\yyparse.cpp -D yyparse.h policy.y */ -#line 74 "policy.y" +// #line 74 "policy.y" #include "stdtwparser.h" @@ -349,7 +349,7 @@ int yy_parse::yynrule = 55; -#line 2 "..\\..\\mkslexyacc\\etc\\yyparse.cpp" +// #line 2 "..\\..\\mkslexyacc\\etc\\yyparse.cpp" // C++ YACC parser code // Copyright 1991 by Mortice Kern Systems Inc. All rights reserved. // @@ -689,22 +689,22 @@ yyEncore: switch (yyi) { /* perform semantic action */ case YYr6: { /* statement : variable_assignment TWP_SEMICOLON */ -#line 194 "policy.y" +// #line 194 "policy.y" cParserHelper::IncrementScopeStatementCount(); } break; case YYr7: { /* statement : global_variable_assignment TWP_SEMICOLON */ -#line 195 "policy.y" +// #line 195 "policy.y" cParserHelper::IncrementScopeStatementCount(); } break; case YYr8: { /* statement : rule TWP_SEMICOLON */ -#line 196 "policy.y" +// #line 196 "policy.y" cParserHelper::IncrementScopeStatementCount(); } break; case YYr12: { /* scoped_block : TWP_LPAREN attribute_list_with_opt_trailing_comma TWP_RPAREN TWP_LBRACE */ -#line 204 "policy.y" +// #line 204 "policy.y" cDebug d("Parse::scope"); @@ -721,7 +721,7 @@ case YYr12: { /* scoped_block : TWP_LPAREN attribute_list_with_opt_trailing_c } break; case YYr13: { /* scoped_block : TWP_LPAREN attribute_list_with_opt_trailing_comma TWP_RPAREN TWP_LBRACE $12 opt_statement_list TWP_RBRACE */ -#line 218 "policy.y" +// #line 218 "policy.y" if( 0 == cParserHelper::GetScopeStatementCount() && iUserNotify::GetInstance()->GetVerboseLevel() == iUserNotify::V_VERBOSE ) { @@ -737,7 +737,7 @@ case YYr13: { /* scoped_block : TWP_LPAREN attribute_list_with_opt_trailing_c } break; case YYr14: { /* directive_block : TWP_IFHOST host_name_list */ -#line 234 "policy.y" +// #line 234 "policy.y" cDebug d("Parse::#ifhost"); @@ -763,7 +763,7 @@ case YYr14: { /* directive_block : TWP_IFHOST host_name_list */ } break; case YYr15: { /* directive_block : TWP_IFHOST host_name_list $14 opt_statement_list opt_else_host TWP_ENDIF */ -#line 257 "policy.y" +// #line 257 "policy.y" cDebug d("Parse::#endif"); cPreprocessor::PopState(); @@ -773,7 +773,7 @@ case YYr15: { /* directive_block : TWP_IFHOST host_name_list $14 opt_statemen } break; case YYr16: { /* directive_block : TWP_SECTION string */ -#line 264 "policy.y" +// #line 264 "policy.y" cDebug d("Parse::#section"); @@ -787,7 +787,7 @@ case YYr16: { /* directive_block : TWP_SECTION string */ } break; case YYr17: { /* directive_block : TWP_ERROR string */ -#line 275 "policy.y" +// #line 275 "policy.y" if( cPreprocessor::GetState() == cPreprocessor::STATE_ACCEPT && !cParserHelper::ParseOnly() ) { @@ -801,7 +801,7 @@ case YYr17: { /* directive_block : TWP_ERROR string */ } break; case YYr18: { /* directive_block : TWP_ECHO string */ -#line 286 "policy.y" +// #line 286 "policy.y" if( cPreprocessor::GetState() == cPreprocessor::STATE_ACCEPT && !cParserHelper::ParseOnly() ) { @@ -814,7 +814,7 @@ case YYr18: { /* directive_block : TWP_ECHO string */ } break; case YYr19: { /* host_name_list : host_name_list TWP_OROR host_name */ -#line 299 "policy.y" +// #line 299 "policy.y" yyval.mpStringList = yypvt[-2].mpStringList; yyval.mpStringList->push_back( *yypvt[0].mpString ); @@ -822,7 +822,7 @@ case YYr19: { /* host_name_list : host_name_list TWP_OROR host_name */ } break; case YYr20: { /* host_name_list : host_name */ -#line 304 "policy.y" +// #line 304 "policy.y" yyval.mpStringList = new cParseStringList; yyval.mpStringList->push_back( *yypvt[0].mpString ); @@ -830,7 +830,7 @@ case YYr20: { /* host_name_list : host_name */ } break; case YYr21: { /* opt_else_host : TWP_ELSE */ -#line 312 "policy.y" +// #line 312 "policy.y" cDebug d("Parse::#else"); @@ -848,7 +848,7 @@ case YYr21: { /* opt_else_host : TWP_ELSE */ } break; case YYr24: { /* variable_assignment : variable_name TWP_EQUALS multi_string */ -#line 332 "policy.y" +// #line 332 "policy.y" cDebug d("Parse::variable_assignment"); @@ -869,7 +869,7 @@ case YYr24: { /* variable_assignment : variable_name TWP_EQUALS multi_string } break; case YYr25: { /* global_variable_assignment : global_string TWP_EQUALS global_multi_string */ -#line 353 "policy.y" +// #line 353 "policy.y" cDebug d("Parse::global variable_assignment"); @@ -890,7 +890,7 @@ case YYr25: { /* global_variable_assignment : global_string TWP_EQUALS global } break; case YYr26: { /* rule : fco_name TWP_RARROW spec_masks */ -#line 374 "policy.y" +// #line 374 "policy.y" cDebug d("Parse::rule(fco_name TWP_RARROW spec_masks)"); if( cPreprocessor::GetState() == cPreprocessor::STATE_IGNORE ) @@ -935,7 +935,7 @@ case YYr26: { /* rule : fco_name TWP_RARROW spec_masks */ } break; case YYr27: { /* rule : TWP_BANG fco_name */ -#line 416 "policy.y" +// #line 416 "policy.y" cDebug d("Parse::rule(!fconame)"); @@ -966,7 +966,7 @@ case YYr27: { /* rule : TWP_BANG fco_name */ } break; case YYr28: { /* spec_masks : prop_vector opt_spec_attributes */ -#line 447 "policy.y" +// #line 447 "policy.y" if( cPreprocessor::GetState() == cPreprocessor::STATE_ACCEPT ) { @@ -987,28 +987,28 @@ case YYr28: { /* spec_masks : prop_vector opt_spec_attributes */ } break; case YYr29: { /* opt_spec_attributes : TWP_LPAREN attribute_list_with_opt_trailing_comma TWP_RPAREN */ -#line 485 "policy.y" +// #line 485 "policy.y" yyval.mpAttrList = yypvt[-1].mpAttrList; } break; case YYr30: { /* opt_spec_attributes : */ -#line 489 "policy.y" +// #line 489 "policy.y" yyval.mpAttrList = new cParseNamedAttrList; } break; case YYr31: { /* attribute_list_with_opt_trailing_comma : attribute_list opt_comma */ -#line 515 "policy.y" +// #line 515 "policy.y" yyval.mpAttrList = yypvt[-1].mpAttrList; } break; case YYr32: { /* attribute_list : attribute_list TWP_COMMA attribute */ -#line 522 "policy.y" +// #line 522 "policy.y" cDebug d("Parse::attribute_list"); ASSERT( yypvt[-2].mpAttrList && yypvt[0].mpAttr ); @@ -1024,7 +1024,7 @@ case YYr32: { /* attribute_list : attribute_list TWP_COMMA attribute */ } break; case YYr33: { /* attribute_list : attribute */ -#line 535 "policy.y" +// #line 535 "policy.y" cDebug d("Parse::attribute_list"); @@ -1038,7 +1038,7 @@ case YYr33: { /* attribute_list : attribute */ } break; case YYr34: { /* attribute : attribute_name TWP_EQUALS attribute_value */ -#line 548 "policy.y" +// #line 548 "policy.y" cDebug d("Parse::attribute"); @@ -1055,7 +1055,7 @@ case YYr34: { /* attribute : attribute_name TWP_EQUALS attribute_value */ } break; case YYr37: { /* variable : TWP_DOLLAR TWP_LPAREN variable_name TWP_RPAREN */ -#line 618 "policy.y" +// #line 618 "policy.y" cDebug d( " parser::variable" ); @@ -1082,7 +1082,7 @@ case YYr37: { /* variable : TWP_DOLLAR TWP_LPAREN variable_name TWP_RPAREN */ } break; case YYr38: { /* prop_vector : multi_string */ -#line 662 "policy.y" +// #line 662 "policy.y" yyval.mpString = new cParseString; *yyval.mpString = ConcatenateStrings( yypvt[0].mpStringList ); @@ -1091,7 +1091,7 @@ case YYr38: { /* prop_vector : multi_string */ } break; case YYr39: { /* attribute_name : string */ -#line 671 "policy.y" +// #line 671 "policy.y" cDebug d(" parser::string(attribute_name)"); yyval.mpString = yypvt[0].mpString; @@ -1099,7 +1099,7 @@ case YYr39: { /* attribute_name : string */ } break; case YYr40: { /* attribute_value : multi_string */ -#line 679 "policy.y" +// #line 679 "policy.y" yyval.mpString = new cParseString; cDebug d(" parser::multi_string(attribute_value)"); @@ -1109,7 +1109,7 @@ case YYr40: { /* attribute_value : multi_string */ } break; case YYr41: { /* fco_name : multi_string */ -#line 689 "policy.y" +// #line 689 "policy.y" cDebug d(" parser::multi_string(fco_name)"); yyval.mpStringList = yypvt[0].mpStringList; @@ -1117,7 +1117,7 @@ case YYr41: { /* fco_name : multi_string */ } break; case YYr42: { /* fco_name : multi_string TWP_PIPE multi_string */ -#line 695 "policy.y" +// #line 695 "policy.y" yypvt[-2].mpStringList->push_back( _T("|") ); @@ -1129,7 +1129,7 @@ case YYr42: { /* fco_name : multi_string TWP_PIPE multi_string */ } break; case YYr43: { /* host_name : string */ -#line 710 "policy.y" +// #line 710 "policy.y" cDebug d(" parser::multi_string(host_name)"); @@ -1138,7 +1138,7 @@ case YYr43: { /* host_name : string */ } break; case YYr44: { /* variable_name : TWP_STRING */ -#line 719 "policy.y" +// #line 719 "policy.y" cDebug d(" parser::string(variable_name)"); yyval.mpString = yypvt[0].mpString; @@ -1146,7 +1146,7 @@ case YYr44: { /* variable_name : TWP_STRING */ } break; case YYr45: { /* multi_string : multi_string string */ -#line 728 "policy.y" +// #line 728 "policy.y" yyval.mpStringList->push_back( *yypvt[0].mpString ); delete yypvt[0].mpString; @@ -1154,7 +1154,7 @@ case YYr45: { /* multi_string : multi_string string */ } break; case YYr46: { /* multi_string : string */ -#line 733 "policy.y" +// #line 733 "policy.y" yyval.mpStringList = new cParseStringList; yyval.mpStringList->push_back( *yypvt[0].mpString ); @@ -1163,7 +1163,7 @@ case YYr46: { /* multi_string : string */ } break; case YYr47: { /* global_multi_string : global_multi_string global_string */ -#line 742 "policy.y" +// #line 742 "policy.y" yyval.mpStringList->push_back( *yypvt[0].mpString ); delete yypvt[0].mpString; @@ -1171,7 +1171,7 @@ case YYr47: { /* global_multi_string : global_multi_string global_string */ } break; case YYr48: { /* global_multi_string : global_string */ -#line 747 "policy.y" +// #line 747 "policy.y" yyval.mpStringList = new cParseStringList; yyval.mpStringList->push_back( *yypvt[0].mpString ); @@ -1180,7 +1180,7 @@ case YYr48: { /* global_multi_string : global_string */ } break; case YYr49: { /* string : TWP_STRING */ -#line 757 "policy.y" +// #line 757 "policy.y" cDebug d(" parser::string(normal)"); d.TraceNever("--(STRING)--> got string (%s)\n", yypvt[0].mpString); @@ -1189,7 +1189,7 @@ case YYr49: { /* string : TWP_STRING */ } break; case YYr50: { /* string : variable */ -#line 763 "policy.y" +// #line 763 "policy.y" cDebug d(" parser::string(normal)"); d.TraceNever("--(STRING)--> got string (%s)\n", yypvt[0].mpString); @@ -1198,14 +1198,14 @@ case YYr50: { /* string : variable */ } break; case YYr51: { /* global_string : TWP_GLOBAL_STRING */ -#line 772 "policy.y" +// #line 772 "policy.y" cDebug d(" parser::string(normal)"); d.TraceNever("--(STRING)--> got string (%s)\n", yypvt[0].mpString); yyval.mpString = yypvt[0].mpString; } break; -#line 343 "..\\..\\mkslexyacc\\etc\\yyparse.cpp" +// #line 343 "..\\..\\mkslexyacc\\etc\\yyparse.cpp" case YYrACCEPT: YYACCEPT; case YYrERROR: From 265bc4701e6fc1a180013f6ef1f1c22170680d9b Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Fri, 25 Aug 2017 21:37:15 -0700 Subject: [PATCH 03/29] Turn #ifdef YACC_WINDOWS to #if 0 to make sure untested & unused code stays unused. --- src/twparser/yyparse.cpp | 10 +++++----- src/twparser/yyparse.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/twparser/yyparse.cpp b/src/twparser/yyparse.cpp index 2c9e610..b90765e 100644 --- a/src/twparser/yyparse.cpp +++ b/src/twparser/yyparse.cpp @@ -428,7 +428,7 @@ yy_parse::~yy_parse() #endif } -#ifdef YACC_WINDOWS +#if 0 //YACC_WINDOWS // The initial portion of the yacc parser. // In an windows environment, it will load the desired @@ -533,7 +533,7 @@ yy_parse::yyparse(yy_scan* ps) #endif /* YACC_WINDOWS */ { -#ifdef YACC_WINDOWS +#if 0 //YACC_WINDOWS short far *yyp; // needed as res tables locked in far memory short far *yyq; #else @@ -594,7 +594,7 @@ yyEncore: #endif } #endif -#ifdef YACC_WINDOWS +#if 0 //YACC_WINDOWS if (yystate >= Sizeof_yypact) /* simple state */ #else /* YACC_WINDOWS */ if (yystate >= (int)sizeof yypact/(int)sizeof yypact[0]) /* simple state */ @@ -640,7 +640,7 @@ yyEncore: * Fell through - take default action */ -#ifdef YACC_WINDOWS +#if 0 //YACC_WINDOWS if (yystate >= Sizeof_yydef) /* simple state */ #else /* YACC_WINDOWS */ if (yystate >= (int)sizeof yydef /(int)sizeof yydef[0]) @@ -1265,7 +1265,7 @@ yyError: , yytp-- #endif ) { -#ifdef YACC_WINDOWS +#if 0 //YACC_WINDOWS if (*yyps >= Sizeof_yypact) /* simple state */ #else /* YACC_WINDOWS */ if (*yyps >= (int)sizeof yypact/(int)sizeof yypact[0]) diff --git a/src/twparser/yyparse.h b/src/twparser/yyparse.h index 612b2a7..38e588a 100644 --- a/src/twparser/yyparse.h +++ b/src/twparser/yyparse.h @@ -133,7 +133,7 @@ typedef struct yyTypedRules_tag { /* Typed rule table */ } yyTypedRules; #endif -#ifdef YACC_WINDOWS +#if 0 // YACC_WINDOWS // include all windows prototypes, macros, constants, etc. @@ -155,7 +155,7 @@ extern HANDLE hInst; class yy_parse { protected: -#ifdef YACC_WINDOWS +#if 0 // YACC_WINDOWS // protected member function for actual scanning From 92580983ecad8d1c740e1a1939fce8a81c070a6f Mon Sep 17 00:00:00 2001 From: brc0x1 Date: Fri, 25 Aug 2017 04:43:52 -0700 Subject: [PATCH 04/29] Remove more leakage in cHashTable & policy parser --- src/core/hashtable.h | 10 +++++++--- src/twparser/genreparseinfo.cpp | 2 ++ src/twparser/yyparse.cpp | 3 +++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/core/hashtable.h b/src/core/hashtable.h index d3194f1..2944ea3 100644 --- a/src/core/hashtable.h +++ b/src/core/hashtable.h @@ -254,10 +254,14 @@ inline void cHashTableIter::SeekNextV { if(mpCurNode) mpCurNode = mpCurNode->next; - //mCurIndex++; - while((! mpCurNode) && (mCurIndex < mHashTable.mTableSize)) + + // if we're out of range, bail out w/o incrementing index + if(mCurIndex >= mHashTable.mTableSize) + return; + + while((! mpCurNode) && (++mCurIndex < mHashTable.mTableSize)) { - mpCurNode = mHashTable.mTable[++mCurIndex]; + mpCurNode = mHashTable.mTable[mCurIndex]; } } diff --git a/src/twparser/genreparseinfo.cpp b/src/twparser/genreparseinfo.cpp index ddcd68d..1e45d96 100644 --- a/src/twparser/genreparseinfo.cpp +++ b/src/twparser/genreparseinfo.cpp @@ -141,6 +141,8 @@ void cGenreParseInfo::InitPredefinedVariables() { mLocalPredefVarTable.Insert( sVarName, sValue ); } + + delete pGU; } diff --git a/src/twparser/yyparse.cpp b/src/twparser/yyparse.cpp index b90765e..715d27a 100644 --- a/src/twparser/yyparse.cpp +++ b/src/twparser/yyparse.cpp @@ -927,6 +927,7 @@ case YYr26: { /* rule : fco_name TWP_RARROW spec_masks */ // add to our lists cParserHelper::GetGenreInfo()->AddStopPoint( fcoName ); cParserHelper::GetGenreInfo()->AddRule( pnode ); + delete pGU; } delete yypvt[-2].mpStringList; @@ -959,6 +960,7 @@ case YYr27: { /* rule : TWP_BANG fco_name */ // add to stop list cParserHelper::GetGenreInfo()->AddStopPoint( fcoName ); + delete pGU; } delete yypvt[0].mpStringList; @@ -978,6 +980,7 @@ case YYr28: { /* spec_masks : prop_vector opt_spec_attributes */ yypvt[0].mpAttrList->MergeNoOverwrite( cParserHelper::GetGlobalAttrList() ); yyval.mpNode = pNode; + delete pGU; } delete yypvt[-1].mpString; From 236d67b9416307d139fde81c78ca5d3ecfb1923f Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sat, 26 Aug 2017 10:07:27 -0700 Subject: [PATCH 05/29] Sort out a valgrind issue w/ handling TEMPDIRECTORY paths. Clean up formatting in twcmdline's FillOutConfigInfo(). --- src/tripwire/twcmdline.cpp | 303 ++++++++++++++++++++----------------- 1 file changed, 168 insertions(+), 135 deletions(-) diff --git a/src/tripwire/twcmdline.cpp b/src/tripwire/twcmdline.cpp index 3db01b8..c4745d8 100644 --- a/src/tripwire/twcmdline.cpp +++ b/src/tripwire/twcmdline.cpp @@ -254,52 +254,66 @@ static void InitCmdLineCommon(cCmdLineParser& parser) /////////////////////////////////////////////////////////////////////////////// static void FillOutConfigInfo(cTWModeCommon* pModeInfo, const cConfigFile& cf) { - TSTRING str; - if(cf.Lookup(TSTRING(_T("POLFILE")), str)) - pModeInfo->mPolFile = str; - if(cf.Lookup(TSTRING(_T("DBFILE")), str)) - pModeInfo->mDbFile = str; - if(cf.Lookup(TSTRING(_T("SITEKEYFILE")), str)) - pModeInfo->mSiteKeyFile = str; - if(cf.Lookup(TSTRING(_T("LOCALKEYFILE")), str)) - pModeInfo->mLocalKeyFile = str; - if(cf.Lookup(TSTRING(_T("REPORTFILE")), str)) - pModeInfo->mReportFile = str; - if(cf.Lookup(TSTRING(_T("EDITOR")), str)) - pModeInfo->mEditor = str; - if(cf.Lookup(TSTRING(_T("LATEPROMPTING")), str)) + TSTRING str; + if(cf.Lookup(TSTRING(_T("POLFILE")), str)) { - if (_tcsicmp(str.c_str(), _T("true")) == 0) - pModeInfo->mbLatePassphrase = true; - } - if(cf.Lookup(TSTRING(_T("RESETACCESSTIME")), str)) - { - // We do not support reset access time on Unix, so we issue a warning. - // This used to be a fatal error, however this prevents - // cross platform config files. - cTWUtil::PrintErrorMsg(eTWInvalidConfigFileKey(_T("RESETACCESSTIME"), eError::NON_FATAL)); + pModeInfo->mPolFile = str; } - if(cf.Lookup(TSTRING(_T("LOOSEDIRECTORYCHECKING")), str)) + if(cf.Lookup(TSTRING(_T("DBFILE")), str)) { - if (_tcsicmp(str.c_str(), _T("true")) == 0) - pModeInfo->mfLooseDirs = true; + pModeInfo->mDbFile = str; + } + if(cf.Lookup(TSTRING(_T("SITEKEYFILE")), str)) + { + pModeInfo->mSiteKeyFile = str; + } + if(cf.Lookup(TSTRING(_T("LOCALKEYFILE")), str)) + { + pModeInfo->mLocalKeyFile = str; + } + if(cf.Lookup(TSTRING(_T("REPORTFILE")), str)) + { + pModeInfo->mReportFile = str; + } + if(cf.Lookup(TSTRING(_T("EDITOR")), str)) + { + pModeInfo->mEditor = str; + } + if(cf.Lookup(TSTRING(_T("LATEPROMPTING")), str)) + { + if (_tcsicmp(str.c_str(), _T("true")) == 0) + pModeInfo->mbLatePassphrase = true; } + if(cf.Lookup(TSTRING(_T("RESETACCESSTIME")), str)) + { + // We do not support reset access time on Unix, so we issue a warning. + // This used to be a fatal error, however this prevents + // cross platform config files. + cTWUtil::PrintErrorMsg(eTWInvalidConfigFileKey(_T("RESETACCESSTIME"), eError::NON_FATAL)); + } + if(cf.Lookup(TSTRING(_T("LOOSEDIRECTORYCHECKING")), str)) + { + if (_tcsicmp(str.c_str(), _T("true")) == 0) + pModeInfo->mfLooseDirs = true; + } - TSTRING temp_directory; - cf.Lookup(TSTRING(_T("TEMPDIRECTORY")), temp_directory); + TSTRING temp_directory; + cf.Lookup(TSTRING(_T("TEMPDIRECTORY")), temp_directory); - if (temp_directory.length() == 0) { + if (temp_directory.empty()) + { #if IS_AROS - temp_directory = "T:"; + temp_directory = "T:"; #else - temp_directory = "/tmp/"; + temp_directory = "/tmp/"; #endif } // make sure we have a trailing slash -- thanks Jarno... // - if (temp_directory[_tcslen(str.c_str())-1] != '/') { - temp_directory += '/'; + if (temp_directory.back() != '/') + { + temp_directory.push_back('/'); } // make sure it exists... // @@ -308,41 +322,43 @@ static void FillOutConfigInfo(cTWModeCommon* pModeInfo, const cConfigFile& cf) temp_directory = cDevicePath::AsNative(temp_directory); #endif - if (access(temp_directory.c_str(), F_OK) != 0) { - TSTRING errStr = TSS_GetString( cCore, core::STR_BAD_TEMPDIRECTORY ); - TSTRING tmpStr = _T("Directory: "); - tmpStr += (temp_directory + _T("\n")); - tmpStr += errStr; - throw eTWInvalidTempDirectory(tmpStr); - } - else { - iFSServices::GetInstance()->SetTempDirName(temp_directory); - } - - - if (cf.Lookup(TSTRING(_T("GLOBALEMAIL")), str)) { - - if (str.length() != 0) - pModeInfo->mGlobalEmail = str; - } - - // - // Set the report-viewing level if one has been specified, use - // default level otherwise. - // - if(cf.Lookup(TSTRING(_T("EMAILREPORTLEVEL")), str)) + if (access(temp_directory.c_str(), F_OK) != 0) { - if (_tcsicmp(str.c_str(), _T("0")) == 0) - pModeInfo->mEmailReportLevel = cTextReportViewer::SINGLE_LINE; - else if (_tcsicmp(str.c_str(), _T("1")) == 0) - pModeInfo->mEmailReportLevel = cTextReportViewer::PARSEABLE; - else if (_tcsicmp(str.c_str(), _T("2")) == 0) - pModeInfo->mEmailReportLevel = cTextReportViewer::SUMMARY_ONLY; - else if (_tcsicmp(str.c_str(), _T("3")) == 0) - pModeInfo->mEmailReportLevel = cTextReportViewer::CONCISE_REPORT; - else if (_tcsicmp(str.c_str(), _T("4")) == 0) - pModeInfo->mEmailReportLevel = cTextReportViewer::FULL_REPORT; - else + TSTRING errStr = TSS_GetString( cCore, core::STR_BAD_TEMPDIRECTORY ); + TSTRING tmpStr = _T("Directory: "); + tmpStr += (temp_directory + _T("\n")); + tmpStr += errStr; + throw eTWInvalidTempDirectory(tmpStr); + } + else + { + iFSServices::GetInstance()->SetTempDirName(temp_directory); + } + + + if (cf.Lookup(TSTRING(_T("GLOBALEMAIL")), str)) + { + if (str.length() != 0) + pModeInfo->mGlobalEmail = str; + } + + // + // Set the report-viewing level if one has been specified, use + // default level otherwise. + // + if(cf.Lookup(TSTRING(_T("EMAILREPORTLEVEL")), str)) + { + if (_tcsicmp(str.c_str(), _T("0")) == 0) + pModeInfo->mEmailReportLevel = cTextReportViewer::SINGLE_LINE; + else if (_tcsicmp(str.c_str(), _T("1")) == 0) + pModeInfo->mEmailReportLevel = cTextReportViewer::PARSEABLE; + else if (_tcsicmp(str.c_str(), _T("2")) == 0) + pModeInfo->mEmailReportLevel = cTextReportViewer::SUMMARY_ONLY; + else if (_tcsicmp(str.c_str(), _T("3")) == 0) + pModeInfo->mEmailReportLevel = cTextReportViewer::CONCISE_REPORT; + else if (_tcsicmp(str.c_str(), _T("4")) == 0) + pModeInfo->mEmailReportLevel = cTextReportViewer::FULL_REPORT; + else { // They specified an illegal level, error. TSTRING errStr = _T("Invalid Level: "); @@ -350,24 +366,25 @@ static void FillOutConfigInfo(cTWModeCommon* pModeInfo, const cConfigFile& cf) throw eTWInvalidReportLevelCfg( errStr ); } } - else - // no level was specified in the configuration file, use default. - pModeInfo->mEmailReportLevel = cTextReportViewer::CONCISE_REPORT; - - - // Decide what mail method should be used to email reports - if(cf.Lookup(TSTRING(_T("MAILMETHOD")), str)) + else { - if (_tcsicmp(str.c_str(), _T("SENDMAIL")) == 0) - pModeInfo->mMailMethod = cMailMessage::MAIL_BY_PIPE; - else if( _tcsicmp( str.c_str(), _T("SMTP") ) == 0 ) - pModeInfo->mMailMethod = cMailMessage::MAIL_BY_SMTP; - else - pModeInfo->mMailMethod = cMailMessage::INVALID_METHOD; + // no level was specified in the configuration file, use default. + pModeInfo->mEmailReportLevel = cTextReportViewer::CONCISE_REPORT; } - else + + // Decide what mail method should be used to email reports + if(cf.Lookup(TSTRING(_T("MAILMETHOD")), str)) { - pModeInfo->mMailMethod = cMailMessage::NO_METHOD; + if (_tcsicmp(str.c_str(), _T("SENDMAIL")) == 0) + pModeInfo->mMailMethod = cMailMessage::MAIL_BY_PIPE; + else if( _tcsicmp( str.c_str(), _T("SMTP") ) == 0 ) + pModeInfo->mMailMethod = cMailMessage::MAIL_BY_SMTP; + else + pModeInfo->mMailMethod = cMailMessage::INVALID_METHOD; + } + else + { + pModeInfo->mMailMethod = cMailMessage::NO_METHOD; } #if !SUPPORTS_NETWORKING @@ -375,60 +392,76 @@ static void FillOutConfigInfo(cTWModeCommon* pModeInfo, const cConfigFile& cf) throw eMailSMTPNotSupported(); #endif - // Get the SMTP server - if(cf.Lookup(TSTRING(_T("SMTPHOST")), str)) - pModeInfo->mSmtpHost = str; - else - pModeInfo->mSmtpHost = _T("127.0.0.1"); // this is the default - - // Get the SMTP port number - if(cf.Lookup(TSTRING(_T("SMTPPORT")), str)) + // Get the SMTP server + if(cf.Lookup(TSTRING(_T("SMTPHOST")), str)) { - int i = _ttoi( str.c_str() ); - if( i < 0 || i > SHRT_MAX ) + pModeInfo->mSmtpHost = str; + } + else + { + pModeInfo->mSmtpHost = _T("127.0.0.1"); // this is the default + } + + // Get the SMTP port number + if(cf.Lookup(TSTRING(_T("SMTPPORT")), str)) + { + int i = _ttoi( str.c_str() ); + if( i < 0 || i > SHRT_MAX ) throw eTWInvalidPortNumber( str ); - pModeInfo->mSmtpPort = static_cast( i ); + pModeInfo->mSmtpPort = static_cast( i ); } - else - pModeInfo->mSmtpPort = 25; // this is the default - - // Get the mail program to use if we're piping our email - if(cf.Lookup(TSTRING(_T("MAILPROGRAM")), str)) - pModeInfo->mMailProgram = str; - else - pModeInfo->mMailProgram.erase(); // MAILPROGRAM is not required to be specified - - // Get the mail program to use if we're piping our email - if(cf.Lookup(TSTRING(_T("MAILNOVIOLATIONS")), str)) + else { - if (_tcsicmp(str.c_str(), _T("true")) == 0) - pModeInfo->mMailNoViolations = true; - else - pModeInfo->mMailNoViolations = false; + pModeInfo->mSmtpPort = 25; // this is the default } - else - pModeInfo->mMailNoViolations = true; // MAILPROGRAM is not required to be specified - if(cf.Lookup(TSTRING(_T("MAILFROMADDRESS")), str)) - pModeInfo->mMailFrom = str; + // Get the mail program to use if we're piping our email + if(cf.Lookup(TSTRING(_T("MAILPROGRAM")), str)) + { + pModeInfo->mMailProgram = str; + } + else + { + pModeInfo->mMailProgram.erase(); // MAILPROGRAM is not required to be specified + } + + // Get the mail program to use if we're piping our email + if(cf.Lookup(TSTRING(_T("MAILNOVIOLATIONS")), str)) + { + if (_tcsicmp(str.c_str(), _T("true")) == 0) + pModeInfo->mMailNoViolations = true; + else + pModeInfo->mMailNoViolations = false; + } + else + { + pModeInfo->mMailNoViolations = true; // MAILPROGRAM is not required to be specified + } + + if(cf.Lookup(TSTRING(_T("MAILFROMADDRESS")), str)) + { + pModeInfo->mMailFrom = str; + } // SYSLOG reporting - if(cf.Lookup(TSTRING(_T("SYSLOGREPORTING")), str)) + if(cf.Lookup(TSTRING(_T("SYSLOGREPORTING")), str)) { #if SUPPORTS_SYSLOG - if (_tcsicmp(str.c_str(), _T("true")) == 0) - pModeInfo->mbLogToSyslog = true; - else - pModeInfo->mbLogToSyslog = false; + if (_tcsicmp(str.c_str(), _T("true")) == 0) + pModeInfo->mbLogToSyslog = true; + else + pModeInfo->mbLogToSyslog = false; #else throw eTWSyslogNotSupported(); #endif } - else - pModeInfo->mbLogToSyslog = false; - + else + { + pModeInfo->mbLogToSyslog = false; + } + // Crossing file systems - if(cf.Lookup(TSTRING(_T("CROSSFILESYSTEMS")), str)) + if(cf.Lookup(TSTRING(_T("CROSSFILESYSTEMS")), str)) { if (_tcsicmp(str.c_str(), _T("true")) == 0) pModeInfo->mbCrossFileSystems = true; @@ -457,20 +490,20 @@ static void FillOutConfigInfo(cTWModeCommon* pModeInfo, const cConfigFile& cf) iFSServices::GetInstance()->SetResolveNames(false); } - // - // turn all of the file names into full paths (they're relative to the exe dir) - // - TSTRING fullPath; - if(iFSServices::GetInstance()->FullPath( fullPath, pModeInfo->mPolFile, cSystemInfo::GetExeDir() )) - pModeInfo->mPolFile = fullPath; - if(iFSServices::GetInstance()->FullPath( fullPath, pModeInfo->mDbFile, cSystemInfo::GetExeDir() )) - pModeInfo->mDbFile = fullPath; - if(iFSServices::GetInstance()->FullPath( fullPath, pModeInfo->mSiteKeyFile, cSystemInfo::GetExeDir() )) - pModeInfo->mSiteKeyFile = fullPath; - if(iFSServices::GetInstance()->FullPath( fullPath, pModeInfo->mLocalKeyFile, cSystemInfo::GetExeDir() )) - pModeInfo->mLocalKeyFile = fullPath; - if(iFSServices::GetInstance()->FullPath( fullPath, pModeInfo->mReportFile, cSystemInfo::GetExeDir() )) - pModeInfo->mReportFile = fullPath; + // + // turn all of the file names into full paths (they're relative to the exe dir) + // + TSTRING fullPath; + if(iFSServices::GetInstance()->FullPath( fullPath, pModeInfo->mPolFile, cSystemInfo::GetExeDir() )) + pModeInfo->mPolFile = fullPath; + if(iFSServices::GetInstance()->FullPath( fullPath, pModeInfo->mDbFile, cSystemInfo::GetExeDir() )) + pModeInfo->mDbFile = fullPath; + if(iFSServices::GetInstance()->FullPath( fullPath, pModeInfo->mSiteKeyFile, cSystemInfo::GetExeDir() )) + pModeInfo->mSiteKeyFile = fullPath; + if(iFSServices::GetInstance()->FullPath( fullPath, pModeInfo->mLocalKeyFile, cSystemInfo::GetExeDir() )) + pModeInfo->mLocalKeyFile = fullPath; + if(iFSServices::GetInstance()->FullPath( fullPath, pModeInfo->mReportFile, cSystemInfo::GetExeDir() )) + pModeInfo->mReportFile = fullPath; } /////////////////////////////////////////////////////////////////////////////// From 79933005b7e9633da688290c4456a97a3974f38b Mon Sep 17 00:00:00 2001 From: brc0x1 Date: Fri, 25 Aug 2017 08:12:20 -0700 Subject: [PATCH 06/29] Switch to rbegin() since std::string::back() is a C++11-ism --- src/tripwire/twcmdline.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tripwire/twcmdline.cpp b/src/tripwire/twcmdline.cpp index c4745d8..e692218 100644 --- a/src/tripwire/twcmdline.cpp +++ b/src/tripwire/twcmdline.cpp @@ -311,7 +311,7 @@ static void FillOutConfigInfo(cTWModeCommon* pModeInfo, const cConfigFile& cf) // make sure we have a trailing slash -- thanks Jarno... // - if (temp_directory.back() != '/') + if (*temp_directory.rbegin() != '/') { temp_directory.push_back('/'); } From 3481d2622ad33788116178d4ede19d2d9de017d5 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sat, 26 Aug 2017 16:10:12 -0700 Subject: [PATCH 07/29] Fix another leak (via valgrind), this time in cCryptoArchive --- src/twcrypto/cryptoarchive.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/twcrypto/cryptoarchive.cpp b/src/twcrypto/cryptoarchive.cpp index eabfe53..987da90 100644 --- a/src/twcrypto/cryptoarchive.cpp +++ b/src/twcrypto/cryptoarchive.cpp @@ -116,7 +116,10 @@ cCryptoArchive::~cCryptoArchive() { ASSERT(mAction == MA_UNSTARTED || mAction == MA_UNKNOWN || mAction == MA_FINISHED || mAction == MA_READING); // check we did not leave a buffer unwritten - + + Finish(); + + // Finish() normally zeroes these out, but hey. delete mpDeflator; delete mpInflator; } From b3b74fd76e26621b513ac2fadb4a1d640f00efba Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sun, 27 Aug 2017 17:22:31 -0700 Subject: [PATCH 08/29] Delete cParseRules when we're done with them. I think this is the last real valgrind issue. --- src/twparser/genreparseinfo.cpp | 10 ++++++++++ src/twparser/genreparseinfo.h | 1 + 2 files changed, 11 insertions(+) diff --git a/src/twparser/genreparseinfo.cpp b/src/twparser/genreparseinfo.cpp index 1e45d96..98e5c43 100644 --- a/src/twparser/genreparseinfo.cpp +++ b/src/twparser/genreparseinfo.cpp @@ -75,6 +75,16 @@ cGenreParseInfo::cGenreParseInfo() InitPredefinedVariables(); } +cGenreParseInfo::~cGenreParseInfo() +{ + RuleListType::iterator itr; + for( itr = mRuleList.begin(); itr != mRuleList.end(); ++itr ) + { + delete *itr; + } + +} + /////////////////////////////////////////////////////////////////////////////// // AddStopPoint diff --git a/src/twparser/genreparseinfo.h b/src/twparser/genreparseinfo.h index eef27f7..d3895f8 100644 --- a/src/twparser/genreparseinfo.h +++ b/src/twparser/genreparseinfo.h @@ -80,6 +80,7 @@ class cGenreParseInfo { public: cGenreParseInfo(); + ~cGenreParseInfo(); void AddStopPoint( const cFCOName& name ); // adds the specified path as a stop point -- for now, we just queue it up, From d724c07873c8abd1c1a5053b35c670be95784372 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sun, 27 Aug 2017 22:58:58 -0700 Subject: [PATCH 09/29] Use a static cFSPropDisplayer instead of creating a fresh one each time someone asks. Addresses a valgrind leak that only manifests in interactive db update mode. --- src/fs/fsfactory.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/fs/fsfactory.cpp b/src/fs/fsfactory.cpp index a2a690e..36f40e4 100644 --- a/src/fs/fsfactory.cpp +++ b/src/fs/fsfactory.cpp @@ -76,7 +76,12 @@ iFCOSpec* cFSFactory::CreateSpec(const TSTRING& name, iFCOSpecHelper* pHelper) c iFCOPropDisplayer* cFSFactory::CreatePropDisplayer() const { - return new cFSPropDisplayer(); + static iFCOPropDisplayer* gPropDisplayer = 0; + + if (!gPropDisplayer) + gPropDisplayer = new cFSPropDisplayer(); + + return gPropDisplayer; } iSerRefCountObj::CreateFunc cFSFactory::GetCreateFunc() const From 8bb3669cf7221e1fe716d5ad62ff4f3c9834dbeb Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sun, 27 Aug 2017 23:46:31 -0700 Subject: [PATCH 10/29] Enable SYSLOGREPORTING for test-harness tests, so that syslog code gets exercised in testing. --- src/test-harness/twtools.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test-harness/twtools.pm b/src/test-harness/twtools.pm index e74fddd..e575e8e 100644 --- a/src/test-harness/twtools.pm +++ b/src/test-harness/twtools.pm @@ -54,7 +54,7 @@ BEGIN { EMAILREPORTLEVEL => '3', REPORTLEVEL => '3', MAILMETHOD => 'SENDMAIL', - SYSLOGREPORTING => 'false', + SYSLOGREPORTING => 'true', MAILPROGRAM => 'cat', MAILFROMADDRESS => 'taz@cat' ); From 7310422053ad1a16d45de3e982cdc541bf780257 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Mon, 28 Aug 2017 20:08:38 -0700 Subject: [PATCH 11/29] Clean up iCodeConverter singleton on exit --- src/core/codeconvert.cpp | 6 ++++++ src/core/codeconvert.h | 2 ++ src/core/core.cpp | 5 ++++- src/core/core.h | 1 + 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/core/codeconvert.cpp b/src/core/codeconvert.cpp index 559d335..7978278 100644 --- a/src/core/codeconvert.cpp +++ b/src/core/codeconvert.cpp @@ -111,6 +111,12 @@ iCodeConverter* iCodeConverter::GetInstance() return m_pInst; } +void iCodeConverter::Finit() +{ + delete m_pInst; + m_pInst = 0; +} + iCodeConverter* iCodeConverter::CreateConverter() { cDebug d("iCodeConverter::CreateConverter()"); diff --git a/src/core/codeconvert.h b/src/core/codeconvert.h index 3c74661..1539a72 100644 --- a/src/core/codeconvert.h +++ b/src/core/codeconvert.h @@ -93,6 +93,8 @@ class iCodeConverter public: static iCodeConverter* GetInstance(); // Singleton + static void Finit(); + /// Subclass Responsibilities diff --git a/src/core/core.cpp b/src/core/core.cpp index a84ebb2..039400a 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -60,5 +60,8 @@ cCore::cCore() iCodeConverter::GetInstance(); } - +cCore::~cCore() +{ + iCodeConverter::Finit(); +} diff --git a/src/core/core.h b/src/core/core.h index 87c3621..3e17c6b 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -54,6 +54,7 @@ TSS_BeginPackage( cCore ) public: cCore(); + ~cCore(); TSS_EndPackage( cCore ) From 78b09e081f7f19337057ed2e85e91418642c9fe1 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Mon, 28 Aug 2017 22:28:30 -0700 Subject: [PATCH 12/29] Add configure options for instrumentation: --enable-coverage & --enable-profiling --- configure | 28 ++++++++++++++++++++++++++++ configure.ac | 16 ++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/configure b/configure index 3052a28..2e91224 100755 --- a/configure +++ b/configure @@ -750,6 +750,8 @@ enable_silent_rules enable_extrawarnings enable_static enable_debug +enable_coverage +enable_profiling enable_dependency_tracking enable_commoncrypto enable_iconv @@ -1395,6 +1397,8 @@ Optional Features: —-disable-extrawarnings do not compile with -Wextra warnings enabled --enable-static compile static binaries --enable-debug compile with debuging enabled + --enable-coverage enable code coverage + --enable-profiling enable profiling --enable-dependency-tracking do not reject slow dependency extractors --disable-dependency-tracking @@ -3497,6 +3501,30 @@ $as_echo "#define NDEBUG 1" >>confdefs.h fi +# Check whether --enable-coverage was given. +if test "${enable_coverage+set}" = set; then : + enableval=$enable_coverage; +fi + +if test "x$enable_coverage" = xyes +then + CFLAGS="${CFLAGS} --coverage" + CXXFLAGS="${CXXFLAGS} --coverage" + LDFLAGS="${LDFLAGS} --coverage" +fi + +# Check whether --enable-profiling was given. +if test "${enable_profiling+set}" = set; then : + enableval=$enable_profiling; +fi + +if test "x$enable_profiling" = xyes +then + CFLAGS="${CFLAGS} -pg" + CXXFLAGS="${CXXFLAGS} -pg" + LDFLAGS="${LDFLAGS} -pg" +fi + ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' diff --git a/configure.ac b/configure.ac index f5a55ca..8c0d96a 100644 --- a/configure.ac +++ b/configure.ac @@ -44,6 +44,22 @@ else AC_DEFINE(NDEBUG, 1, [Compile without debug code]) fi +AC_ARG_ENABLE(coverage, [ --enable-coverage enable code coverage]) +if test "x$enable_coverage" = xyes +then + CFLAGS="${CFLAGS} --coverage" + CXXFLAGS="${CXXFLAGS} --coverage" + LDFLAGS="${LDFLAGS} --coverage" +fi + +AC_ARG_ENABLE(profiling, [ --enable-profiling enable profiling]) +if test "x$enable_profiling" = xyes +then + CFLAGS="${CFLAGS} -pg" + CXXFLAGS="${CXXFLAGS} -pg" + LDFLAGS="${LDFLAGS} -pg" +fi + dnl ################### dnl Checks for programs dnl ################### From 02dd677d714bdcd8fe48f49f7df02cfedb8e5c49 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Mon, 28 Aug 2017 23:01:35 -0700 Subject: [PATCH 13/29] Tweak .gitignore to ignore gcov files; add a convenience script (lcov.sh) to run lcov & package results --- .gitignore | 3 +++ lcov.sh | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100755 lcov.sh diff --git a/.gitignore b/.gitignore index 9e8c92b..14e685b 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,9 @@ src/test-harness/twtest **/*.dll **/*.exe **/*~ +**/*# **/*.bak **/.DS_Store +**/*.gcno +**/*.gcda releases/ diff --git a/lcov.sh b/lcov.sh new file mode 100755 index 0000000..b8f85c5 --- /dev/null +++ b/lcov.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +if [ -d ./lcov ]; then + rm -Rf ./lcov +fi + +if [ -e ./lcov.dat ]; then + rm ./lcov.dat +fi + +if [ -e ./lcov.tgz ]; then + rm ./lcov.tgz +fi + +lcov --capture --directory src --output-file ./lcov.dat +genhtml ./lcov.dat --output-directory lcov +tar -zcvf lcov.tgz lcov + From 5a34e6f48c2cc478a9e9b62d3683007689a98f61 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Tue, 29 Aug 2017 18:57:59 -0700 Subject: [PATCH 14/29] Add a 'targets' make target to list make targets. Also add a 'test' target as an alias of 'check'. --- Makefile.am | 6 ++++++ Makefile.in | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/Makefile.am b/Makefile.am index d9ee690..e353377 100644 --- a/Makefile.am +++ b/Makefile.am @@ -17,3 +17,9 @@ check: rm -Rf $(top_srcdir)/bin/TWTestData cd $(top_srcdir)/src/test-harness && perl ./twtest.pl cd $(top_srcdir)/bin && ./twtest all + +test: check + +.PHONY: targets +targets: + @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs diff --git a/Makefile.in b/Makefile.in index 0a11cca..bdfa8ff 100644 --- a/Makefile.in +++ b/Makefile.in @@ -813,6 +813,13 @@ check: cd $(top_srcdir)/src/test-harness && perl ./twtest.pl cd $(top_srcdir)/bin && ./twtest all +test: check + +.PHONY: targets +targets: + @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make dat\ +a base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: From 7fe1e4f79abc13743b0d078d944fa3e0bc48a133 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Thu, 31 Aug 2017 18:50:02 -0700 Subject: [PATCH 15/29] Detect support for doors & event ports in a proper autoconf way. --- config.h.in | 12 ++++++++++ configure | 46 +++++++++++++++++++++++++++++++++++++ configure.ac | 6 +++++ src/core/unixfsservices.cpp | 12 ++++++---- 4 files changed, 72 insertions(+), 4 deletions(-) diff --git a/config.h.in b/config.h.in index f7c8937..184a9f7 100644 --- a/config.h.in +++ b/config.h.in @@ -24,6 +24,12 @@ /* Has /dev/urandom */ #undef HAVE_DEV_URANDOM +/* Define to 1 if you have the `door_create' function. */ +#undef HAVE_DOOR_CREATE + +/* Define to 1 if you have the header file. */ +#undef HAVE_DOOR_H + /* Define to 1 if you have the header file. */ #undef HAVE_FCNTL_H @@ -63,6 +69,12 @@ /* Define to 1 if you have the header file. */ #undef HAVE_OPENSSL_SHA_H +/* Define to 1 if you have the `port_create' function. */ +#undef HAVE_PORT_CREATE + +/* Define to 1 if you have the header file. */ +#undef HAVE_PORT_H + /* Define to 1 if you have the `posix_fadvise' function. */ #undef HAVE_POSIX_FADVISE diff --git a/configure b/configure index 2e91224..5c6690e 100755 --- a/configure +++ b/configure @@ -6214,6 +6214,52 @@ done fi +for ac_header in door.h +do : + ac_fn_c_check_header_mongrel "$LINENO" "door.h" "ac_cv_header_door_h" "$ac_includes_default" +if test "x$ac_cv_header_door_h" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_DOOR_H 1 +_ACEOF + for ac_func in door_create +do : + ac_fn_c_check_func "$LINENO" "door_create" "ac_cv_func_door_create" +if test "x$ac_cv_func_door_create" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_DOOR_CREATE 1 +_ACEOF + +fi +done + +fi + +done + + +for ac_header in port.h +do : + ac_fn_c_check_header_mongrel "$LINENO" "port.h" "ac_cv_header_port_h" "$ac_includes_default" +if test "x$ac_cv_header_port_h" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_PORT_H 1 +_ACEOF + for ac_func in port_create +do : + ac_fn_c_check_func "$LINENO" "port_create" "ac_cv_func_port_create" +if test "x$ac_cv_func_port_create" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_PORT_CREATE 1 +_ACEOF + +fi +done + +fi + +done + + if test -c "/dev/random"; then diff --git a/configure.ac b/configure.ac index 8c0d96a..8b995a8 100644 --- a/configure.ac +++ b/configure.ac @@ -150,6 +150,12 @@ then AC_CHECK_HEADERS(CommonCrypto/CommonDigest.h) fi +dnl check for door support (Solaris) +AC_CHECK_HEADERS(door.h, [AC_CHECK_FUNCS(door_create)]) + +dnl check for event port support (Solaris) +AC_CHECK_HEADERS(port.h, [AC_CHECK_FUNCS(port_create)]) + dnl ############################################## dnl check for various RNG/PRNG devices dnl ############################################## diff --git a/src/core/unixfsservices.cpp b/src/core/unixfsservices.cpp index 0f91d1e..92ba8e8 100644 --- a/src/core/unixfsservices.cpp +++ b/src/core/unixfsservices.cpp @@ -365,10 +365,12 @@ void cUnixFSServices::Stat( const TSTRING& strNameC, cFSStatArgs& stat) const #ifdef S_ISSOCK else if(S_ISSOCK(statbuf.st_mode)) stat.mFileType = cFSStatArgs::TY_SOCK; #endif -#ifdef S_IFDOOR + +#if HAVE_DOOR_CREATE else if(S_ISDOOR(statbuf.st_mode)) stat.mFileType = cFSStatArgs::TY_DOOR; #endif -#ifdef S_ISPORT + +#if HAVE_PORT_CREATE else if(S_ISPORT(statbuf.st_mode)) stat.mFileType = cFSStatArgs::TY_PORT; #endif @@ -594,12 +596,14 @@ void cUnixFSServices::ConvertModeToString( uint64 perm, TSTRING& tstrPerm ) cons case S_IFLNK: szPerm[0] = _T('l'); break; -#ifdef S_IFDOOR + +#if HAVE_DOOR_CREATE // Solaris doors case S_IFDOOR: szPerm[0] = _T('D'); break; #endif -#ifdef S_ISPORT + +#if HAVE_PORT_CREATE // Solaris event ports case S_IFPORT: szPerm[0] = _T('P'); break; From 5184fe01c4903ae290ef9f1fbc4a61fc584ce97a Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Thu, 31 Aug 2017 19:51:50 -0700 Subject: [PATCH 16/29] Customize 'make clean' to also remove test data dirs and gcov files --- src/Makefile.am | 4 ++++ src/Makefile.in | 28 +++++++++++++++++----------- src/core/Makefile.am | 1 + src/core/Makefile.in | 2 ++ src/cryptlib/Makefile.am | 2 +- src/cryptlib/Makefile.in | 2 +- src/db/Makefile.am | 1 + src/db/Makefile.in | 2 ++ src/fco/Makefile.am | 1 + src/fco/Makefile.in | 2 ++ src/fs/Makefile.am | 1 + src/fs/Makefile.in | 2 ++ src/siggen/Makefile.am | 2 +- src/siggen/Makefile.in | 2 +- src/tripwire/Makefile.am | 2 +- src/tripwire/Makefile.in | 2 +- src/tw/Makefile.am | 1 + src/tw/Makefile.in | 2 ++ src/twadmin/Makefile.am | 2 +- src/twadmin/Makefile.in | 2 +- src/twcrypto/Makefile.am | 1 + src/twcrypto/Makefile.in | 2 ++ src/twparser/Makefile.am | 1 + src/twparser/Makefile.in | 2 ++ src/twprint/Makefile.am | 2 +- src/twprint/Makefile.in | 2 +- src/twtest/Makefile.am | 8 +++++++- src/twtest/Makefile.in | 29 +++++++++++++++++------------ src/util/Makefile.am | 1 + src/util/Makefile.in | 2 ++ 30 files changed, 79 insertions(+), 34 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 6b8084e..7e6ffd8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,3 +8,7 @@ install: uninstall: true +clean-local: clean-local-check +.PHONY: clean-local-check +clean-local-check: + -rm -rf test-harness/twtest \ No newline at end of file diff --git a/src/Makefile.in b/src/Makefile.in index f0fb88f..be0d740 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -519,7 +519,7 @@ maintainer-clean-generic: @echo "it deletes files that may require special tools to rebuild." clean: clean-recursive -clean-am: clean-generic mostlyclean-am +clean-am: clean-generic clean-local mostlyclean-am distclean: distclean-recursive -rm -f Makefile @@ -586,16 +586,17 @@ uninstall-am: .MAKE: $(am__recursive_targets) install-am install-strip .PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am check \ - check-am clean clean-generic cscopelist-am ctags ctags-am \ - distclean distclean-generic distclean-tags distdir dvi dvi-am \ - html html-am info info-am install install-am install-data \ - install-data-am install-dvi install-dvi-am install-exec \ - install-exec-am install-html install-html-am install-info \ - install-info-am install-man install-pdf install-pdf-am \ - install-ps install-ps-am install-strip installcheck \ - installcheck-am installdirs installdirs-am maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-generic pdf \ - pdf-am ps ps-am tags tags-am uninstall uninstall-am + check-am clean clean-generic clean-local cscopelist-am ctags \ + ctags-am distclean distclean-generic distclean-tags distdir \ + dvi dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs installdirs-am \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-generic pdf pdf-am ps ps-am tags tags-am uninstall \ + uninstall-am .PRECIOUS: Makefile @@ -606,6 +607,11 @@ install: uninstall: true +clean-local: clean-local-check +.PHONY: clean-local-check +clean-local-check: + -rm -rf test-harness/twtest + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 0a47f0e..2b48224 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -35,6 +35,7 @@ libcore_a_LIBADD = @CORE_CRYPT_O@ libcore_a_DEPENDENCIES = @CORE_CRYPT_O@ DEFS = @DEFS@ # This gets rid of the -I. so AM_CPPFLAGS must be more explicit +CLEANFILES = *.gcno *.gcda all: $(noinst_LIBRARIES) $(AR) ru ../../lib/libtripwire.a $(libcore_a_OBJECTS) $(libcore_a_LIBADD) diff --git a/src/core/Makefile.in b/src/core/Makefile.in index 694e8f0..5ee6d53 100644 --- a/src/core/Makefile.in +++ b/src/core/Makefile.in @@ -358,6 +358,7 @@ libcore_a_HEADERS = archive.h charutil.h cmdlineparser.h codeconvert.h \ libcore_a_LIBADD = @CORE_CRYPT_O@ libcore_a_DEPENDENCIES = @CORE_CRYPT_O@ +CLEANFILES = *.gcno *.gcda all: all-am .SUFFIXES: @@ -544,6 +545,7 @@ install-strip: mostlyclean-generic: clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) diff --git a/src/cryptlib/Makefile.am b/src/cryptlib/Makefile.am index 6ec973b..156082d 100644 --- a/src/cryptlib/Makefile.am +++ b/src/cryptlib/Makefile.am @@ -20,7 +20,7 @@ libcryptlib_a_HEADERS = \ ztrees.h DEFS = @DEFS@ # This gets rid of the -I. so AM_CPPFLAGS must be more explicit -CLEANFILES = ../../lib/libcryptlib.a +CLEANFILES = ../../lib/libcryptlib.a *.gcno *.gcda all: $(noinst_LIBRARIES) $(LN) -f $(noinst_LIBRARIES) ../../lib/libcryptlib.a diff --git a/src/cryptlib/Makefile.in b/src/cryptlib/Makefile.in index 5306cab..4f6d772 100644 --- a/src/cryptlib/Makefile.in +++ b/src/cryptlib/Makefile.in @@ -333,7 +333,7 @@ libcryptlib_a_HEADERS = \ queue.h rng.h sha.h smartptr.h words.h zbits.h zdeflate.h zinflate.h \ ztrees.h -CLEANFILES = ../../lib/libcryptlib.a +CLEANFILES = ../../lib/libcryptlib.a *.gcno *.gcda all: all-am .SUFFIXES: diff --git a/src/db/Makefile.am b/src/db/Makefile.am index 3488413..68a57ed 100644 --- a/src/db/Makefile.am +++ b/src/db/Makefile.am @@ -13,6 +13,7 @@ libdb_a_HEADERS = \ db.h dberrors.h hierdatabase.h hierdbnode.h hierdbpath.h stddb.h DEFS = @DEFS@ # This gets rid of the -I. so AM_CPPFLAGS must be more explicit +CLEANFILES = *.gcno *.gcda all: $(noinst_LIBRARIES) $(AR) ru ../../lib/libtripwire.a $(libdb_a_OBJECTS) diff --git a/src/db/Makefile.in b/src/db/Makefile.in index 53ef6f8..c875d47 100644 --- a/src/db/Makefile.in +++ b/src/db/Makefile.in @@ -324,6 +324,7 @@ libdb_a_HEADERS = \ block.h blockfile.h blockrecordarray.h blockrecordfile.h \ db.h dberrors.h hierdatabase.h hierdbnode.h hierdbpath.h stddb.h +CLEANFILES = *.gcno *.gcda all: all-am .SUFFIXES: @@ -510,6 +511,7 @@ install-strip: mostlyclean-generic: clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) diff --git a/src/fco/Makefile.am b/src/fco/Makefile.am index 10f756d..cb5f50f 100644 --- a/src/fco/Makefile.am +++ b/src/fco/Makefile.am @@ -27,6 +27,7 @@ libfco_a_HEADERS = \ DEFS = @DEFS@ # This gets rid of the -I. so AM_CPPFLAGS must be more explicit +CLEANFILES = *.gcno *.gcda all: $(noinst_LIBRARIES) $(AR) ru ../../lib/libtripwire.a $(libfco_a_OBJECTS) diff --git a/src/fco/Makefile.in b/src/fco/Makefile.in index 84b5a63..0300072 100644 --- a/src/fco/Makefile.in +++ b/src/fco/Makefile.in @@ -345,6 +345,7 @@ libfco_a_HEADERS = \ iterproxy.h parsergenreutil.h propset.h signature.h \ stdfco.h twfactory.h +CLEANFILES = *.gcno *.gcda all: all-am .SUFFIXES: @@ -531,6 +532,7 @@ install-strip: mostlyclean-generic: clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am index 55fbd36..d7b7ae5 100644 --- a/src/fs/Makefile.am +++ b/src/fs/Makefile.am @@ -17,6 +17,7 @@ libfs_a_HEADERS = \ fsvisitor.h stdfs.h DEFS = @DEFS@ # This gets rid of the -I. so AM_CPPFLAGS must be more explicit +CLEANFILES = *.gcno *.gcda all: $(noinst_LIBRARIES) $(AR) ru ../../lib/libtripwire.a $(libfs_a_OBJECTS) diff --git a/src/fs/Makefile.in b/src/fs/Makefile.in index 7a90d6e..21c6d25 100644 --- a/src/fs/Makefile.in +++ b/src/fs/Makefile.in @@ -331,6 +331,7 @@ libfs_a_HEADERS = \ fspropcalc.h fspropdisplayer.h fspropset.h fsstrings.h \ fsvisitor.h stdfs.h +CLEANFILES = *.gcno *.gcda all: all-am .SUFFIXES: @@ -517,6 +518,7 @@ install-strip: mostlyclean-generic: clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) diff --git a/src/siggen/Makefile.am b/src/siggen/Makefile.am index b56566e..f400881 100644 --- a/src/siggen/Makefile.am +++ b/src/siggen/Makefile.am @@ -16,7 +16,7 @@ siggen_HEADERS = \ siggen.h siggencmdline.h siggenstrings.h stdsiggen.h DEFS = @DEFS@ # This gets rid of the -I. so AM_CPPFLAGS must be more explicit -CLEANFILES = ../../bin/siggen +CLEANFILES = ../../bin/siggen *.gcno *.gcda all: $(sbin_PROGRAMS) @test -d ../../bin && $(LN) -f $(sbin_PROGRAMS) ../../bin diff --git a/src/siggen/Makefile.in b/src/siggen/Makefile.in index 563a92c..8db2435 100644 --- a/src/siggen/Makefile.in +++ b/src/siggen/Makefile.in @@ -318,7 +318,7 @@ siggen_SOURCES = \ siggen_HEADERS = \ siggen.h siggencmdline.h siggenstrings.h stdsiggen.h -CLEANFILES = ../../bin/siggen +CLEANFILES = ../../bin/siggen *.gcno *.gcda all: all-am .SUFFIXES: diff --git a/src/tripwire/Makefile.am b/src/tripwire/Makefile.am index 4abba88..2ec808a 100644 --- a/src/tripwire/Makefile.am +++ b/src/tripwire/Makefile.am @@ -20,7 +20,7 @@ tripwire_HEADERS = \ tripwirestrings.h tripwireutil.h twcmdline.h twcmdlineutil.h updatedb.h DEFS = @DEFS@ # This gets rid of the -I. so AM_CPPFLAGS must be more explicit -CLEANFILES = ../../bin/tripwire ../../lib/libtripwire.a +CLEANFILES = ../../bin/tripwire ../../lib/libtripwire.a *.gcno *.gcda all: $(sbin_PROGRAMS) @test -d ../../bin && $(LN) -f $(sbin_PROGRAMS) ../../bin diff --git a/src/tripwire/Makefile.in b/src/tripwire/Makefile.in index 7d343a3..df8e69c 100644 --- a/src/tripwire/Makefile.in +++ b/src/tripwire/Makefile.in @@ -326,7 +326,7 @@ tripwire_HEADERS = \ stdtripwire.h syslog_trip.h tripwire.h tripwireerrors.h tripwiremsg.h \ tripwirestrings.h tripwireutil.h twcmdline.h twcmdlineutil.h updatedb.h -CLEANFILES = ../../bin/tripwire ../../lib/libtripwire.a +CLEANFILES = ../../bin/tripwire ../../lib/libtripwire.a *.gcno *.gcda all: all-am .SUFFIXES: diff --git a/src/tw/Makefile.am b/src/tw/Makefile.am index de2d025..1bea795 100644 --- a/src/tw/Makefile.am +++ b/src/tw/Makefile.am @@ -20,6 +20,7 @@ libtw_a_HEADERS = \ tw.h twerrors.h twinit.h twstrings.h twutil.h DEFS = @DEFS@ -DCONFIG_DIR=\"$(sysconfdir)\" +CLEANFILES = *.gcno *.gcda all: $(noinst_LIBRARIES) $(AR) ru ../../lib/libtripwire.a $(libtw_a_OBJECTS) diff --git a/src/tw/Makefile.in b/src/tw/Makefile.in index ca3e7d5..8749f14 100644 --- a/src/tw/Makefile.in +++ b/src/tw/Makefile.in @@ -337,6 +337,7 @@ libtw_a_HEADERS = \ stdtw.h systeminfo.h textdbviewer.h textreportviewer.h \ tw.h twerrors.h twinit.h twstrings.h twutil.h +CLEANFILES = *.gcno *.gcda all: all-am .SUFFIXES: @@ -523,6 +524,7 @@ install-strip: mostlyclean-generic: clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) diff --git a/src/twadmin/Makefile.am b/src/twadmin/Makefile.am index b59ec1c..538bde7 100644 --- a/src/twadmin/Makefile.am +++ b/src/twadmin/Makefile.am @@ -17,7 +17,7 @@ twadmin_HEADERS = \ twadmincl.h twadminerrors.h twadminstrings.h DEFS = @DEFS@ # This gets rid of the -I. so AM_CPPFLAGS must be more explicit -CLEANFILES = ../../bin/twadmin +CLEANFILES = ../../bin/twadmin *.gcno *.gcda all: $(sbin_PROGRAMS) @test -d ../../bin && $(LN) -f $(sbin_PROGRAMS) ../../bin diff --git a/src/twadmin/Makefile.in b/src/twadmin/Makefile.in index 0cb82a2..b3a8e68 100644 --- a/src/twadmin/Makefile.in +++ b/src/twadmin/Makefile.in @@ -319,7 +319,7 @@ twadmin_HEADERS = \ keygeneration.h resource.h stdtwadmin.h twadmin.h \ twadmincl.h twadminerrors.h twadminstrings.h -CLEANFILES = ../../bin/twadmin +CLEANFILES = ../../bin/twadmin *.gcno *.gcda all: all-am .SUFFIXES: diff --git a/src/twcrypto/Makefile.am b/src/twcrypto/Makefile.am index 27d1fd3..27aaa0c 100644 --- a/src/twcrypto/Makefile.am +++ b/src/twcrypto/Makefile.am @@ -13,6 +13,7 @@ libtwcrypto_a_HEADERS = \ stdtwcrypto.h twcrypto.h twcryptoerrors.h DEFS = @DEFS@ # This gets rid of the -I. so AM_CPPFLAGS must be more explicit +CLEANFILES = *.gcno *.gcda all: $(noinst_LIBRARIES) $(AR) ru ../../lib/libtripwire.a $(libtwcrypto_a_OBJECTS) diff --git a/src/twcrypto/Makefile.in b/src/twcrypto/Makefile.in index 2b30911..9afae2e 100644 --- a/src/twcrypto/Makefile.in +++ b/src/twcrypto/Makefile.in @@ -325,6 +325,7 @@ libtwcrypto_a_HEADERS = \ bytequeue.h crypto.h cryptoarchive.h keyfile.h \ stdtwcrypto.h twcrypto.h twcryptoerrors.h +CLEANFILES = *.gcno *.gcda all: all-am .SUFFIXES: @@ -511,6 +512,7 @@ install-strip: mostlyclean-generic: clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) diff --git a/src/twparser/Makefile.am b/src/twparser/Makefile.am index bf75900..61fa23d 100644 --- a/src/twparser/Makefile.am +++ b/src/twparser/Makefile.am @@ -15,6 +15,7 @@ libtwparser_a_HEADERS = \ yylex.h yyparse.h DEFS = @DEFS@ # This gets rid of the -I. so AM_CPPFLAGS must be more explicit +CLEANFILES = *.gcno *.gcda all: $(noinst_LIBRARIES) $(AR) ru ../../lib/libtripwire.a $(libtwparser_a_OBJECTS) diff --git a/src/twparser/Makefile.in b/src/twparser/Makefile.in index dc9551b..102f0d9 100644 --- a/src/twparser/Makefile.in +++ b/src/twparser/Makefile.in @@ -328,6 +328,7 @@ libtwparser_a_HEADERS = \ stdtwparser.h twparser.h twparsererrors.h twparserstrings.h \ yylex.h yyparse.h +CLEANFILES = *.gcno *.gcda all: all-am .SUFFIXES: @@ -514,6 +515,7 @@ install-strip: mostlyclean-generic: clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) diff --git a/src/twprint/Makefile.am b/src/twprint/Makefile.am index 7973565..6b09237 100644 --- a/src/twprint/Makefile.am +++ b/src/twprint/Makefile.am @@ -17,7 +17,7 @@ twprint_HEADERS = \ twprinterrors.h twprintstrings.h DEFS = @DEFS@ # This gets rid of the -I. so AM_CPPFLAGS must be more explicit -CLEANFILES = ../../bin/twprint +CLEANFILES = ../../bin/twprint *.gcno *.gcda all: $(sbin_PROGRAMS) @test -d ../../bin && $(LN) -f $(sbin_PROGRAMS) ../../bin diff --git a/src/twprint/Makefile.in b/src/twprint/Makefile.in index 157d67c..afaa7af 100644 --- a/src/twprint/Makefile.in +++ b/src/twprint/Makefile.in @@ -319,7 +319,7 @@ twprint_HEADERS = \ resource.h stdtwprint.h twprint.h twprintcmdline.h \ twprinterrors.h twprintstrings.h -CLEANFILES = ../../bin/twprint +CLEANFILES = ../../bin/twprint *.gcno *.gcda all: all-am .SUFFIXES: diff --git a/src/twtest/Makefile.am b/src/twtest/Makefile.am index 4361ccb..662f936 100644 --- a/src/twtest/Makefile.am +++ b/src/twtest/Makefile.am @@ -81,7 +81,13 @@ wchar16_t.cpp twtest_HEADERS = stdtest.h stringutil_t.h test.h DEFS = @DEFS@ # This gets rid of the -I. so AM_CPPFLAGS must be more explicit -CLEANFILES = ../../bin/twtest + +clean-local: clean-local-check +.PHONY: clean-local-check +clean-local-check: + -rm -rf ../../bin/TWTestData + -rm -f ../../bin/twtest + -rm -f *.gcno *.gcda all: $(sbin_PROGRAMS) @test -d ../../bin && $(LN) -f $(sbin_PROGRAMS) ../../bin diff --git a/src/twtest/Makefile.in b/src/twtest/Makefile.in index 84b0b3e..f3ee9b4 100644 --- a/src/twtest/Makefile.in +++ b/src/twtest/Makefile.in @@ -420,7 +420,6 @@ usernotifystdout_t.cpp \ wchar16_t.cpp twtest_HEADERS = stdtest.h stringutil_t.h test.h -CLEANFILES = ../../bin/twtest all: all-am .SUFFIXES: @@ -645,7 +644,6 @@ install-strip: mostlyclean-generic: clean-generic: - -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) @@ -656,7 +654,7 @@ maintainer-clean-generic: @echo "it deletes files that may require special tools to rebuild." clean: clean-am -clean-am: clean-generic clean-sbinPROGRAMS mostlyclean-am +clean-am: clean-generic clean-local clean-sbinPROGRAMS mostlyclean-am distclean: distclean-am -rm -f Makefile @@ -724,15 +722,15 @@ uninstall-am: uninstall-sbinPROGRAMS uninstall-twtestHEADERS .MAKE: install-am install-strip .PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ - clean-sbinPROGRAMS cscopelist-am ctags ctags-am distclean \ - distclean-compile distclean-generic distclean-tags distdir dvi \ - dvi-am html html-am info info-am install install-am \ - install-data install-data-am install-dvi install-dvi-am \ - install-exec install-exec-am install-html install-html-am \ - install-info install-info-am install-man install-pdf \ - install-pdf-am install-ps install-ps-am install-sbinPROGRAMS \ - install-strip install-twtestHEADERS installcheck \ - installcheck-am installdirs maintainer-clean \ + clean-local clean-sbinPROGRAMS cscopelist-am ctags ctags-am \ + distclean distclean-compile distclean-generic distclean-tags \ + distdir dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-sbinPROGRAMS install-strip install-twtestHEADERS \ + installcheck installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-compile \ mostlyclean-generic pdf pdf-am ps ps-am tags tags-am uninstall \ uninstall-am uninstall-sbinPROGRAMS uninstall-twtestHEADERS @@ -740,6 +738,13 @@ uninstall-am: uninstall-sbinPROGRAMS uninstall-twtestHEADERS .PRECIOUS: Makefile +clean-local: clean-local-check +.PHONY: clean-local-check +clean-local-check: + -rm -rf ../../bin/TWTestData + -rm -f ../../bin/twtest + -rm -f *.gcno *.gcda + all: $(sbin_PROGRAMS) @test -d ../../bin && $(LN) -f $(sbin_PROGRAMS) ../../bin diff --git a/src/util/Makefile.am b/src/util/Makefile.am index a268a3d..bd39842 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -12,6 +12,7 @@ libutil_a_HEADERS = fileutil.h miscutil.h stdutil.h \ stringencoder.h util.h utilerrors.h utilstrings.h DEFS = @DEFS@ # This gets rid of the -I. so AM_CPPFLAGS must be more explicit +CLEANFILES = *.gcno *.gcda all: $(noinst_LIBRARIES) $(AR) ru ../../lib/libtripwire.a $(libutil_a_OBJECTS) diff --git a/src/util/Makefile.in b/src/util/Makefile.in index 8fd445d..96f23e3 100644 --- a/src/util/Makefile.in +++ b/src/util/Makefile.in @@ -323,6 +323,7 @@ libutil_a_SOURCES = \ libutil_a_HEADERS = fileutil.h miscutil.h stdutil.h \ stringencoder.h util.h utilerrors.h utilstrings.h +CLEANFILES = *.gcno *.gcda all: all-am .SUFFIXES: @@ -509,6 +510,7 @@ install-strip: mostlyclean-generic: clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) From 0886ea31befabd24b510fb5b31464268622e111b Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Thu, 31 Aug 2017 21:44:24 -0700 Subject: [PATCH 17/29] Tweak a couple of test-harness tests to exclude variable properties like access time, since tests aren't interested in that behavior. --- src/test-harness/tests/integritycheck.pm | 4 ++-- src/test-harness/tests/polupdate.pm | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test-harness/tests/integritycheck.pm b/src/test-harness/tests/integritycheck.pm index 7e8bbac..a7b8159 100644 --- a/src/test-harness/tests/integritycheck.pm +++ b/src/test-harness/tests/integritycheck.pm @@ -35,12 +35,12 @@ sub PolicyFileString # (rulename="RuleA", severity=30, emailto="elvis@mars") { - $root -> \$(ReadOnly)+S; #read only plus SHA-1 + $root -> \$(ReadOnly) +S -ab; #read only plus SHA-1 minus atime & blocks } (rulename="RuleB", severity=200, emailto="elvis@mars") { - $root2 -> \$(ReadOnly)+S; #read only plus SHA-1 + $root2 -> \$(ReadOnly) +S -ab; #read only plus SHA-1 minus atime & blocks } POLICY_END diff --git a/src/test-harness/tests/polupdate.pm b/src/test-harness/tests/polupdate.pm index 4f701a1..bc4a4d1 100644 --- a/src/test-harness/tests/polupdate.pm +++ b/src/test-harness/tests/polupdate.pm @@ -31,8 +31,8 @@ sub PolicyFileString return < \$(ReadOnly)+M; #read only plus MD5 - $root2 -> \$(ReadOnly)+M; #read only plus MD5 + $root1 -> \$(ReadOnly) +M -ab; #read only plus MD5 minus atime & blocks + $root2 -> \$(ReadOnly) +M -ab; #read only plus MD5 minus atime & blocks POLICY_END @@ -46,8 +46,8 @@ sub PolicyFileStringNew return < \$(ReadOnly)+S; #read only plus SHA1 - $root3 -> \$(ReadOnly)+S; #read only plus SHA1 + $root1 -> \$(ReadOnly) +S -ab; #read only plus SHA1 minus atime & blocks + $root3 -> \$(ReadOnly) +S -ab; #read only plus SHA1 minus atime & blocks POLICY_END From ce25569eeae154664f54ae6f920f53a073a6ab64 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Fri, 1 Sep 2017 13:48:57 -0700 Subject: [PATCH 18/29] Use 0 instead of CHILD_ERROR_NATIVE since the latter only exists in Perl >= 5.14.2, and doesn't seem to have any obvious advantages. --- src/test-harness/twtools.pm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test-harness/twtools.pm b/src/test-harness/twtools.pm index e575e8e..1252162 100644 --- a/src/test-harness/twtools.pm +++ b/src/test-harness/twtools.pm @@ -221,7 +221,7 @@ sub PrintPolicy { my (@out) = `$twrootdir/bin/twadmin -m p -c $twrootdir/$twcfgloc -p $twrootdir/$twpolfileloc -S $twrootdir/$twsitekeyloc $params{opts} 2>&1`; - my ($result) = ${^CHILD_ERROR_NATIVE}; + my ($result) = $?; logStatus(@out); @@ -239,7 +239,7 @@ sub PrintConfig { logStatus "printing config file...\n"; my (@out) = `$twrootdir/bin/twadmin -m f -c $twrootdir/$twcfgloc $params{opts} 2>&1`; - my ($result) = ${^CHILD_ERROR_NATIVE}; + my ($result) = $?; logStatus(@out); @@ -275,7 +275,7 @@ sub GeneratePolicyFile { my (@out) = `$twrootdir/bin/twadmin -m P -c $twrootdir/$twcfgloc -Q $twsitepass -p $twrootdir/$twpolfileloc $twrootdir/$twpolicyloc 2>&1`; - my ($result) = ${^CHILD_ERROR_NATIVE}; + my ($result) = $?; logStatus(@out); @@ -297,7 +297,7 @@ sub CreatePolicy { my (@out) = `$twrootdir/bin/twadmin -m P -c $twrootdir/$twcfgloc -Q $twsitepass -p $twrootdir/$twpolfileloc $params{policy-text} 2>&1`; - my ($result) = ${^CHILD_ERROR_NATIVE}; + my ($result) = $?; logStatus(@out); @@ -315,7 +315,7 @@ sub InitializeDatabase { print "initializing database for '$twmsg' test...\n" if $verbose; my (@out) = `$twrootdir/bin/tripwire -m i -P $twsitepass -p $twrootdir/$twpolfileloc -c $twrootdir/$twcfgloc 2>&1`; - my ($result) = ${^CHILD_ERROR_NATIVE}; + my ($result) = $?; logStatus(@out); @@ -335,7 +335,7 @@ sub UpdateDatabase { print "updating database for '$twmsg' test...\n" if $verbose; my (@out) = `$twrootdir/bin/tripwire -m u -a -P $twsitepass -Z $params{secure-mode} -p $twrootdir/$twpolfileloc -c $twrootdir/$twcfgloc -r $params{report} 2>&1`; - my ($result) = ${^CHILD_ERROR_NATIVE}; + my ($result) = $?; logStatus(@out); From 9d1d1e19d311f4c84bb0daa233d41d04aa10de19 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Fri, 1 Sep 2017 14:18:19 -0700 Subject: [PATCH 19/29] Re-add 'compile' script since make dist/distcheck seem to want it; remove it from .gitignore; recreate root Makefile.in with automake 1.15.1 --- .gitignore | 1 - Makefile.in | 3 +- compile | 348 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 349 insertions(+), 3 deletions(-) create mode 100755 compile diff --git a/.gitignore b/.gitignore index 14e685b..ee3da06 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ config.h config.h.in~ config.log config.status -compile autom4te.cache/ bin/ lib/ diff --git a/Makefile.in b/Makefile.in index bdfa8ff..faf90c5 100644 --- a/Makefile.in +++ b/Makefile.in @@ -817,8 +817,7 @@ test: check .PHONY: targets targets: - @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make dat\ -a base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs + @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/compile b/compile new file mode 100755 index 0000000..2ab71e4 --- /dev/null +++ b/compile @@ -0,0 +1,348 @@ +#! /bin/sh +# Wrapper for compilers which do not understand '-c -o'. + +scriptversion=2016-01-11.22; # UTC + +# Copyright (C) 1999-2017 Free Software Foundation, Inc. +# Written by Tom Tromey . +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# This file is maintained in Automake, please report +# bugs to or send patches to +# . + +nl=' +' + +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent tools from complaining about whitespace usage. +IFS=" "" $nl" + +file_conv= + +# func_file_conv build_file lazy +# Convert a $build file to $host form and store it in $file +# Currently only supports Windows hosts. If the determined conversion +# type is listed in (the comma separated) LAZY, no conversion will +# take place. +func_file_conv () +{ + file=$1 + case $file in + / | /[!/]*) # absolute file, and not a UNC file + if test -z "$file_conv"; then + # lazily determine how to convert abs files + case `uname -s` in + MINGW*) + file_conv=mingw + ;; + CYGWIN*) + file_conv=cygwin + ;; + *) + file_conv=wine + ;; + esac + fi + case $file_conv/,$2, in + *,$file_conv,*) + ;; + mingw/*) + file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` + ;; + cygwin/*) + file=`cygpath -m "$file" || echo "$file"` + ;; + wine/*) + file=`winepath -w "$file" || echo "$file"` + ;; + esac + ;; + esac +} + +# func_cl_dashL linkdir +# Make cl look for libraries in LINKDIR +func_cl_dashL () +{ + func_file_conv "$1" + if test -z "$lib_path"; then + lib_path=$file + else + lib_path="$lib_path;$file" + fi + linker_opts="$linker_opts -LIBPATH:$file" +} + +# func_cl_dashl library +# Do a library search-path lookup for cl +func_cl_dashl () +{ + lib=$1 + found=no + save_IFS=$IFS + IFS=';' + for dir in $lib_path $LIB + do + IFS=$save_IFS + if $shared && test -f "$dir/$lib.dll.lib"; then + found=yes + lib=$dir/$lib.dll.lib + break + fi + if test -f "$dir/$lib.lib"; then + found=yes + lib=$dir/$lib.lib + break + fi + if test -f "$dir/lib$lib.a"; then + found=yes + lib=$dir/lib$lib.a + break + fi + done + IFS=$save_IFS + + if test "$found" != yes; then + lib=$lib.lib + fi +} + +# func_cl_wrapper cl arg... +# Adjust compile command to suit cl +func_cl_wrapper () +{ + # Assume a capable shell + lib_path= + shared=: + linker_opts= + for arg + do + if test -n "$eat"; then + eat= + else + case $1 in + -o) + # configure might choose to run compile as 'compile cc -o foo foo.c'. + eat=1 + case $2 in + *.o | *.[oO][bB][jJ]) + func_file_conv "$2" + set x "$@" -Fo"$file" + shift + ;; + *) + func_file_conv "$2" + set x "$@" -Fe"$file" + shift + ;; + esac + ;; + -I) + eat=1 + func_file_conv "$2" mingw + set x "$@" -I"$file" + shift + ;; + -I*) + func_file_conv "${1#-I}" mingw + set x "$@" -I"$file" + shift + ;; + -l) + eat=1 + func_cl_dashl "$2" + set x "$@" "$lib" + shift + ;; + -l*) + func_cl_dashl "${1#-l}" + set x "$@" "$lib" + shift + ;; + -L) + eat=1 + func_cl_dashL "$2" + ;; + -L*) + func_cl_dashL "${1#-L}" + ;; + -static) + shared=false + ;; + -Wl,*) + arg=${1#-Wl,} + save_ifs="$IFS"; IFS=',' + for flag in $arg; do + IFS="$save_ifs" + linker_opts="$linker_opts $flag" + done + IFS="$save_ifs" + ;; + -Xlinker) + eat=1 + linker_opts="$linker_opts $2" + ;; + -*) + set x "$@" "$1" + shift + ;; + *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) + func_file_conv "$1" + set x "$@" -Tp"$file" + shift + ;; + *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) + func_file_conv "$1" mingw + set x "$@" "$file" + shift + ;; + *) + set x "$@" "$1" + shift + ;; + esac + fi + shift + done + if test -n "$linker_opts"; then + linker_opts="-link$linker_opts" + fi + exec "$@" $linker_opts + exit 1 +} + +eat= + +case $1 in + '') + echo "$0: No command. Try '$0 --help' for more information." 1>&2 + exit 1; + ;; + -h | --h*) + cat <<\EOF +Usage: compile [--help] [--version] PROGRAM [ARGS] + +Wrapper for compilers which do not understand '-c -o'. +Remove '-o dest.o' from ARGS, run PROGRAM with the remaining +arguments, and rename the output as expected. + +If you are trying to build a whole package this is not the +right script to run: please start by reading the file 'INSTALL'. + +Report bugs to . +EOF + exit $? + ;; + -v | --v*) + echo "compile $scriptversion" + exit $? + ;; + cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ + icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) + func_cl_wrapper "$@" # Doesn't return... + ;; +esac + +ofile= +cfile= + +for arg +do + if test -n "$eat"; then + eat= + else + case $1 in + -o) + # configure might choose to run compile as 'compile cc -o foo foo.c'. + # So we strip '-o arg' only if arg is an object. + eat=1 + case $2 in + *.o | *.obj) + ofile=$2 + ;; + *) + set x "$@" -o "$2" + shift + ;; + esac + ;; + *.c) + cfile=$1 + set x "$@" "$1" + shift + ;; + *) + set x "$@" "$1" + shift + ;; + esac + fi + shift +done + +if test -z "$ofile" || test -z "$cfile"; then + # If no '-o' option was seen then we might have been invoked from a + # pattern rule where we don't need one. That is ok -- this is a + # normal compilation that the losing compiler can handle. If no + # '.c' file was seen then we are probably linking. That is also + # ok. + exec "$@" +fi + +# Name of file we expect compiler to create. +cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` + +# Create the lock directory. +# Note: use '[/\\:.-]' here to ensure that we don't use the same name +# that we are using for the .o file. Also, base the name on the expected +# object file name, since that is what matters with a parallel build. +lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d +while true; do + if mkdir "$lockdir" >/dev/null 2>&1; then + break + fi + sleep 1 +done +# FIXME: race condition here if user kills between mkdir and trap. +trap "rmdir '$lockdir'; exit 1" 1 2 15 + +# Run the compile. +"$@" +ret=$? + +if test -f "$cofile"; then + test "$cofile" = "$ofile" || mv "$cofile" "$ofile" +elif test -f "${cofile}bj"; then + test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" +fi + +rmdir "$lockdir" +exit $ret + +# Local Variables: +# mode: shell-script +# sh-indentation: 2 +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC0" +# time-stamp-end: "; # UTC" +# End: From 7a262bf1c163308fe4ce3d8a839991741f627e4b Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Fri, 1 Sep 2017 17:13:57 -0700 Subject: [PATCH 20/29] Fix AROS build issue that crept in somehow --- src/core/msystem.cpp | 2 +- src/twparser/yylex.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/msystem.cpp b/src/core/msystem.cpp index f63c3cb..025442d 100644 --- a/src/core/msystem.cpp +++ b/src/core/msystem.cpp @@ -78,7 +78,7 @@ #include #include #include -#if defined(HAVE_MALLOC_H) +#if HAVE_MALLOC_H && !IS_AROS #include #endif #include diff --git a/src/twparser/yylex.cpp b/src/twparser/yylex.cpp index 5fc5b78..b77935b 100644 --- a/src/twparser/yylex.cpp +++ b/src/twparser/yylex.cpp @@ -515,7 +515,7 @@ const int MIN_NUM_STATES = 20; //#endif #include -#ifdef HAVE_MALLOC_H +#if HAVE_MALLOC_H && !IS_AROS #include #endif #include From 736a761bffbca4dde9016efd3d4abbce5e733210 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Fri, 1 Sep 2017 19:43:05 -0700 Subject: [PATCH 21/29] Fix a couple of twtest-only valgrind issues --- src/twtest/crytpo_t.cpp | 10 +++++++--- src/twtest/fcosetimpl_t.cpp | 11 +++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/twtest/crytpo_t.cpp b/src/twtest/crytpo_t.cpp index 5d83447..d3a0be2 100644 --- a/src/twtest/crytpo_t.cpp +++ b/src/twtest/crytpo_t.cpp @@ -44,9 +44,13 @@ void TestCrypto() const int BUFSIZE = 9000; - char source[BUFSIZE]; - char crypt[COUNT + BUFSIZE]; // needs to be able to hold even number of blocks - char dest[COUNT]; + std::vector source_buf(BUFSIZE); + std::vector crypt_buf(COUNT + BUFSIZE); // needs to be able to hold even number of blocks + std::vector dest_buf(COUNT); + + char* source = &source_buf[0]; + char* crypt = &crypt_buf[0]; + char* dest = &dest_buf[0]; memcpy(source, "I love the smell of the sheep.", 31); diff --git a/src/twtest/fcosetimpl_t.cpp b/src/twtest/fcosetimpl_t.cpp index 1cfc034..153e0d0 100644 --- a/src/twtest/fcosetimpl_t.cpp +++ b/src/twtest/fcosetimpl_t.cpp @@ -75,10 +75,12 @@ void TestFCOSetImpl() pFCO3->Release(); // let's iterate over the fcos - cIterProxy pit(set.GetIter()); + iFCOIter* pIter = set.GetIter(); + cIterProxy pit(pIter); pit->SeekBegin(); PrintIter(pit, d); + // lookup a specific fco cIterProxy pit2(set.Lookup(cFCOName(_T("fco2")))); if(! (iFCOIter*)pit2) @@ -113,10 +115,14 @@ void TestFCOSetImpl() // test operator= cFCOSetImpl set2; set2 = set; - pit = set2.GetIter(); + + pIter->DestroyIter(); + pIter = set2.GetIter(); + pit = pIter; d.TraceDebug("Made a new set and set it equal to the first with operator=; printing out...\n"); PrintIter(pit, d); + // test IsEmpty set.Clear(); TEST(set.IsEmpty()); @@ -142,6 +148,7 @@ void TestFCOSetImpl() pit = set3.GetIter(); PrintIter(pit, d); + pIter->DestroyIter(); d.TraceDebug("Leaving...\n"); return; From 0d21e71407d1904f437dafcf194fcaf4f72bb978 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sun, 3 Sep 2017 00:12:54 -0700 Subject: [PATCH 22/29] Skip crc32 test if 'cksum' is not present for comparison (e.g. SkyOS) --- src/test-harness/tests/crc32.pm | 51 +++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/test-harness/tests/crc32.pm b/src/test-harness/tests/crc32.pm index b694b90..c4bf82d 100644 --- a/src/test-harness/tests/crc32.pm +++ b/src/test-harness/tests/crc32.pm @@ -28,39 +28,46 @@ sub initialize() { # sub run() { - my $twpassed = 1; + my $twpassed = 1; - twtools::logStatus("*** Beginning $description\n"); - printf("%-30s", "-- $description"); + twtools::logStatus("*** Beginning $description\n"); + printf("%-30s", "-- $description"); - # lets see if the system 'cksum' agree's with siggen's crc32 value - # - my ($crc32, undef) = split(/ /, `cksum $twtools::twrootdir/test`); - my $siggen = `$twtools::twrootdir/bin/siggen -h -t -C $twtools::twrootdir/test`; + # lets see if the system 'cksum' agree's with siggen's crc32 value + # + my ($crc32, undef) = split(/ /, `cksum $twtools::twrootdir/test`); - chomp $crc32; - chomp $siggen; + if ($crc32 eq "") { + ++$twtools::twskippedtests; + print "SKIPPED\n"; + return; + } - # cksum issues results in decimal, so get siggen's result in base10. - $siggen = hex($siggen); + my $siggen = `$twtools::twrootdir/bin/siggen -h -t -C $twtools::twrootdir/test`; - twtools::logStatus(" cksum reports: $crc32\n"); - twtools::logStatus("siggen reports: $siggen\n"); + chomp $crc32; + chomp $siggen; - $twpassed = ($crc32 eq $siggen); + # cksum issues results in decimal, so get siggen's result in base10. + $siggen = hex($siggen); - ######################################################### - # - # See if the tests all succeeded... - # - if ($twpassed) { + twtools::logStatus(" cksum reports: $crc32\n"); + twtools::logStatus("siggen reports: $siggen\n"); + + $twpassed = ($crc32 eq $siggen); + + ######################################################### + # + # See if the tests all succeeded... + # + if ($twpassed) { print "PASSED\n"; ++$twtools::twpassedtests; - } - else { + } + else { ++$twtools::twfailedtests; print "*FAILED*\n"; - } + } } From 8c73f1cf3b024b9a8dcc0ebc3a0720c3248c65e1 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sun, 3 Sep 2017 20:28:24 -0700 Subject: [PATCH 23/29] Rework unit test framework (such as it is) to refer to tests by name & not numeric id. Mark tests as skipped if they don't make any TEST assertions or are skipped explicitly --- src/twtest/archive_t.cpp | 4 + src/twtest/blockfile_t.cpp | 6 + src/twtest/blockrecordarray_t.cpp | 4 + src/twtest/charutil_t.cpp | 12 +- src/twtest/cmdlineparser_t.cpp | 7 + src/twtest/codeconvert_t.cpp | 12 +- src/twtest/configfile_t.cpp | 6 + src/twtest/cryptoarchive_t.cpp | 5 +- src/twtest/crytpo_t.cpp | 5 + src/twtest/dbdatasource_t.cpp | 5 + src/twtest/debug_t.cpp | 5 +- src/twtest/displayencoder_t.cpp | 23 +- src/twtest/error_t.cpp | 5 + src/twtest/errorbucketimpl_t.cpp | 4 + src/twtest/fcocompare_t.cpp | 5 + src/twtest/fcodatabasefile_t.cpp | 7 + src/twtest/fconame_t.cpp | 5 +- src/twtest/fconametbl_t.cpp | 5 + src/twtest/fconametranslator_t.cpp | 4 + src/twtest/fcopropimpl_t.cpp | 4 + src/twtest/fcopropvector_t.cpp | 5 + src/twtest/fcoreport_t.cpp | 4 + src/twtest/fcosetimpl_t.cpp | 4 + src/twtest/fcospec_t.cpp | 5 + src/twtest/fcospecattr_t.cpp | 5 + src/twtest/fcospechelper_t.cpp | 5 + src/twtest/fcospeclist_t.cpp | 4 + src/twtest/fcospecutil_t.cpp | 5 + src/twtest/file_t.cpp | 4 + src/twtest/fileheader_t.cpp | 5 + src/twtest/fileutil_t.cpp | 4 + src/twtest/fsdatasourceiter_t.cpp | 5 + src/twtest/fsobject_t.cpp | 7 + src/twtest/fspropcalc_t.cpp | 6 +- src/twtest/fspropdisplayer_t.cpp | 4 + src/twtest/fspropset_t.cpp | 5 + src/twtest/fsspec_t.cpp | 4 + src/twtest/genre_t.cpp | 29 +- src/twtest/genrespeclist_t.cpp | 9 + src/twtest/genreswitcher_t.cpp | 31 +- src/twtest/growheap_t.cpp | 4 + src/twtest/hashtable_t.cpp | 15 +- src/twtest/hierdatabase_t.cpp | 5 + src/twtest/keyfile_t.cpp | 4 + src/twtest/platform_t.cpp | 7 + src/twtest/policyparser_t.cpp | 8 +- src/twtest/refcountobj_t.cpp | 5 + src/twtest/resources_t.cpp | 5 +- src/twtest/serializer_t.cpp | 6 + src/twtest/serializerimpl_t.cpp | 4 + src/twtest/signature_t.cpp | 4 + src/twtest/srefcountobj_t.cpp | 4 + src/twtest/stringencoder_t.cpp | 4 + src/twtest/stringutil_t.h | 5 + src/twtest/tasktimer_t.cpp | 6 + src/twtest/tchar_t.cpp | 5 + src/twtest/test.cpp | 492 +++++++++++++++++------------ src/twtest/test.h | 17 +- src/twtest/textreportviewer_t.cpp | 6 +- src/twtest/twlocale_t.cpp | 8 + src/twtest/twutil_t.cpp | 5 + src/twtest/types_t.cpp | 5 + src/twtest/unixfsservices_t.cpp | 5 +- src/twtest/usernotifystdout_t.cpp | 6 + src/twtest/wchar16_t.cpp | 5 + 65 files changed, 650 insertions(+), 273 deletions(-) diff --git a/src/twtest/archive_t.cpp b/src/twtest/archive_t.cpp index e2e479d..3db5e8a 100644 --- a/src/twtest/archive_t.cpp +++ b/src/twtest/archive_t.cpp @@ -186,3 +186,7 @@ void TestArchive() } } +void RegisterSuite_Archive() +{ + RegisterTest("Archive", "Basic", TestArchive); +} diff --git a/src/twtest/blockfile_t.cpp b/src/twtest/blockfile_t.cpp index 9fb8712..9788af3 100644 --- a/src/twtest/blockfile_t.cpp +++ b/src/twtest/blockfile_t.cpp @@ -109,3 +109,9 @@ void TestBlockFile() bf.Close(); } + +void RegisterSuite_BlockFile() +{ + RegisterTest("BlockFile", "Basic", TestBlockFile); +} + diff --git a/src/twtest/blockrecordarray_t.cpp b/src/twtest/blockrecordarray_t.cpp index 4242f98..a1a3b34 100644 --- a/src/twtest/blockrecordarray_t.cpp +++ b/src/twtest/blockrecordarray_t.cpp @@ -125,3 +125,7 @@ void TestBlockRecordArray() #endif } +void RegisterSuite_BlockRecordArray() +{ + RegisterTest("BlockRecordArray", "Basic", TestBlockRecordArray); +} diff --git a/src/twtest/charutil_t.cpp b/src/twtest/charutil_t.cpp index c55d7cc..827f5ef 100644 --- a/src/twtest/charutil_t.cpp +++ b/src/twtest/charutil_t.cpp @@ -75,11 +75,7 @@ void TestCharUtilBasic() PrintChars( _T("fo\x23 54") ); } - -/* -TSS_BeginTestSuiteFrom( cCharEncoderTest ) - - TSS_AddTestCase( Basic ); - -TSS_EndTestSuite( cCharEncoderTest ) -*/ +void RegisterSuite_CharUtil() +{ + RegisterTest("CharUtil", "Basic", TestCharUtilBasic); +} diff --git a/src/twtest/cmdlineparser_t.cpp b/src/twtest/cmdlineparser_t.cpp index a58de3e..d4898de 100644 --- a/src/twtest/cmdlineparser_t.cpp +++ b/src/twtest/cmdlineparser_t.cpp @@ -161,3 +161,10 @@ void TestCmdLineParser() // TODO -- test a bunch more!!! } +void RegisterSuite_CmdLineParser() +{ + RegisterTest("CmdLineParser", "Basic", TestCmdLineParser); +} + + + diff --git a/src/twtest/codeconvert_t.cpp b/src/twtest/codeconvert_t.cpp index a5947f0..7700f0d 100644 --- a/src/twtest/codeconvert_t.cpp +++ b/src/twtest/codeconvert_t.cpp @@ -185,7 +185,8 @@ char NonZeroChar( char ch ) //TestMbToDb in codeconvert_t.cpp seems to hit an infinite loop or runs verrrry long; ifdef'd" void TestMbToDb() { - TCERR << "\nTODO: TestMbToDb in codeconvert_t.cpp is flaky & needs to be fixed/replaced; currently disabled." << std::endl; + skip("This test is flaky & needs to be fixed/replaced; currently disabled."); + #if 0 std::string s; s.resize( 0x10000 * 2 ); // two bytes for each combination @@ -240,7 +241,8 @@ void TestMbToDb() // dbchar_t to mbchar_t void TestDbToMb() { - TCERR << "\nTODO: TestDbToMb in codeconvert_t.cpp fails, most likely due to not speaking UTF-16. Should fix this." << std::endl; + skip("This test fails, most likely due to not speaking UTF-16. Should fix this."); + #if 0 wc16_string ws; wc16_string::size_type n; @@ -344,4 +346,8 @@ bool LowASCIILooksLikeUCS2InWchart() } #endif - +void RegisterSuite_CodeConvert() +{ + RegisterTest("CodeConvert", "MbToDb", TestMbToDb); + RegisterTest("CodeConvert", "DbToMb", TestDbToMb); +} diff --git a/src/twtest/configfile_t.cpp b/src/twtest/configfile_t.cpp index 2e7b479..d62b03e 100644 --- a/src/twtest/configfile_t.cpp +++ b/src/twtest/configfile_t.cpp @@ -177,3 +177,9 @@ void TestConfigFile2(void) d.TraceDetail("Tests Passed!\n"); //#endif // NOT_BRIANS_TEST } + +void RegisterSuite_ConfigFile() +{ + RegisterTest("ConfigFile", "Basic 1", TestConfigFile); + RegisterTest("ConfigFile", "Basic 2", TestConfigFile2); +} diff --git a/src/twtest/cryptoarchive_t.cpp b/src/twtest/cryptoarchive_t.cpp index 292a9a4..3b754a4 100644 --- a/src/twtest/cryptoarchive_t.cpp +++ b/src/twtest/cryptoarchive_t.cpp @@ -299,4 +299,7 @@ void TestCryptoArchive() #endif } - +void RegisterSuite_CryptoArchive() +{ + RegisterTest("CryptoArchive", "Basic", TestCryptoArchive); +} diff --git a/src/twtest/crytpo_t.cpp b/src/twtest/crytpo_t.cpp index d3a0be2..018f4bb 100644 --- a/src/twtest/crytpo_t.cpp +++ b/src/twtest/crytpo_t.cpp @@ -416,3 +416,8 @@ void TestCrypto() } } +void RegisterSuite_Crypto() +{ + RegisterTest("Crypto", "Basic", TestCrypto); +} + diff --git a/src/twtest/dbdatasource_t.cpp b/src/twtest/dbdatasource_t.cpp index 52680f9..c5d5b73 100644 --- a/src/twtest/dbdatasource_t.cpp +++ b/src/twtest/dbdatasource_t.cpp @@ -212,3 +212,8 @@ void TestDbDataSourceBasic() db.AssertAllBlocksValid(); #endif } + +void RegisterSuite_DbDataSource() +{ + RegisterTest("DbDataSource", "Basic", TestDbDataSourceBasic); +} diff --git a/src/twtest/debug_t.cpp b/src/twtest/debug_t.cpp index ad0d9f6..2b3be0f 100644 --- a/src/twtest/debug_t.cpp +++ b/src/twtest/debug_t.cpp @@ -90,4 +90,7 @@ void TestDebug() d.TraceDebug("Exiting...\n"); } - +void RegisterSuite_Debug() +{ + RegisterTest("Debug", "Basic", TestDebug); +} diff --git a/src/twtest/displayencoder_t.cpp b/src/twtest/displayencoder_t.cpp index 3ec8406..df98865 100644 --- a/src/twtest/displayencoder_t.cpp +++ b/src/twtest/displayencoder_t.cpp @@ -321,17 +321,16 @@ void TestDisplayEncoderBasic() // make sure there are '\' and '"' in it ) } -/*TSS_BeginTestSuiteFrom( cDisplayEncoderTest ) - - TSS_AddTestCase( Basic ); - TSS_AddTestCase( TestHexToChar ); - TSS_AddTestCase( TestCharToHex ); - TSS_AddTestCase( TestStringToHex ); - TSS_AddTestCase( TestHexToString ); - TSS_AddTestCase( TestUnconvertable ); - TSS_AddTestCase( TestUnprintable ); - TSS_AddTestCase( TestQuoteAndBackSlash ); - -TSS_EndTestSuite( cDisplayEncoderTest )*/ +void RegisterSuite_DisplayEncoder() +{ + RegisterTest("DisplayEncoder", "Basic", TestDisplayEncoderBasic); + RegisterTest("DisplayEncoder", "CharToHex", TestCharToHex); + RegisterTest("DisplayEncoder", "HexToChar", TestHexToChar); + RegisterTest("DisplayEncoder", "StringToHex", TestStringToHex); + RegisterTest("DisplayEncoder", "HexToString", TestHexToString); + //RegisterTest("DisplayEncoder", "Unconvertable", TestUnconvertable); + //RegisterTest("DisplayEncoder", "Unprintable", TestUnprintable); + RegisterTest("DisplayEncoder", "QuoteAndBackSlash", TestQuoteAndBackSlash); +} diff --git a/src/twtest/error_t.cpp b/src/twtest/error_t.cpp index 4ab7e35..f3ed526 100644 --- a/src/twtest/error_t.cpp +++ b/src/twtest/error_t.cpp @@ -81,3 +81,8 @@ void TestError() TEST(threw); } + +void RegisterSuite_Error() +{ + RegisterTest("Error", "Basic", TestError); +} diff --git a/src/twtest/errorbucketimpl_t.cpp b/src/twtest/errorbucketimpl_t.cpp index 2a677c2..0ab4184 100644 --- a/src/twtest/errorbucketimpl_t.cpp +++ b/src/twtest/errorbucketimpl_t.cpp @@ -143,3 +143,7 @@ void TestErrorBucketImpl() } +void RegisterSuite_ErrorBucketImpl() +{ + RegisterTest("ErrorBucketImpl", "Basic", TestErrorBucketImpl); +} diff --git a/src/twtest/fcocompare_t.cpp b/src/twtest/fcocompare_t.cpp index f4580ba..752a8f4 100644 --- a/src/twtest/fcocompare_t.cpp +++ b/src/twtest/fcocompare_t.cpp @@ -158,3 +158,8 @@ void TestFCOCompare() return; } + +void RegisterSuite_FCOCompare() +{ + RegisterTest("FCOCompare", "Basic", TestFCOCompare); +} diff --git a/src/twtest/fcodatabasefile_t.cpp b/src/twtest/fcodatabasefile_t.cpp index 551ba15..0e1d19f 100644 --- a/src/twtest/fcodatabasefile_t.cpp +++ b/src/twtest/fcodatabasefile_t.cpp @@ -32,9 +32,16 @@ // fcodatabasefile.cpp #include "tw/stdtw.h" #include "tw/fcodatabasefile.h" +#include "test.h" void TestFCODatabaseFile() { cDebug d("TestFCODatabaseFile"); d.TraceError("Implement this!\n"); + skip("TestFCODatabaseFile not implemented"); +} + +void RegisterSuite_FCODatabaseFile() +{ + RegisterTest("FCODatabaseFile", "Basic", TestFCODatabaseFile); } diff --git a/src/twtest/fconame_t.cpp b/src/twtest/fconame_t.cpp index 4be3a5b..7ef2f54 100644 --- a/src/twtest/fconame_t.cpp +++ b/src/twtest/fconame_t.cpp @@ -139,4 +139,7 @@ void TestFCOName() } } - +void RegisterSuite_FCOName() +{ + RegisterTest("FCOName", "Basic", TestFCOName); +} diff --git a/src/twtest/fconametbl_t.cpp b/src/twtest/fconametbl_t.cpp index b1bba5f..a0e2dbd 100644 --- a/src/twtest/fconametbl_t.cpp +++ b/src/twtest/fconametbl_t.cpp @@ -61,3 +61,8 @@ void TestFCONameTbl() pNode4->Release(); pNode5->Release(); } + +void RegisterSuite_FCONameTbl() +{ + RegisterTest("FCONameTbl", "Basic", TestFCONameTbl); +} diff --git a/src/twtest/fconametranslator_t.cpp b/src/twtest/fconametranslator_t.cpp index 2a32416..fd4bae3 100644 --- a/src/twtest/fconametranslator_t.cpp +++ b/src/twtest/fconametranslator_t.cpp @@ -115,3 +115,7 @@ void TestUnprintable( const TCHAR* pchName, const TCHAR* pchGenre ) TEST( fcoNameNew == fcoName ); } +void RegisterSuite_FCONameTranslator() +{ + RegisterTest("FCONameTranslator", "Basic", TestFCONameTranslator); +} diff --git a/src/twtest/fcopropimpl_t.cpp b/src/twtest/fcopropimpl_t.cpp index 8cda935..492a36f 100644 --- a/src/twtest/fcopropimpl_t.cpp +++ b/src/twtest/fcopropimpl_t.cpp @@ -94,3 +94,7 @@ void TestFCOPropImpl() return; } +void RegisterSuite_FCOPropImpl() +{ + RegisterTest("FCOPropImpl", "Basic", TestFCOPropImpl); +} diff --git a/src/twtest/fcopropvector_t.cpp b/src/twtest/fcopropvector_t.cpp index 699a085..5b4bf27 100644 --- a/src/twtest/fcopropvector_t.cpp +++ b/src/twtest/fcopropvector_t.cpp @@ -192,3 +192,8 @@ static void objManip (cFCOPropVector &testV, cDebug& d) v3.AddItem(3); TEST((v1 ^ v2) == v3); } + +void RegisterSuite_FCOPropVector() +{ + RegisterTest("FCOPropVector", "Basic", TestFCOPropVector); +} diff --git a/src/twtest/fcoreport_t.cpp b/src/twtest/fcoreport_t.cpp index 8dfea82..1a91220 100644 --- a/src/twtest/fcoreport_t.cpp +++ b/src/twtest/fcoreport_t.cpp @@ -171,3 +171,7 @@ void TestFCOReport() d.TraceDebug("Leaving...\n"); } +void RegisterSuite_FCOReport() +{ + RegisterTest("FCOReport", "Basic", TestFCOReport); +} diff --git a/src/twtest/fcosetimpl_t.cpp b/src/twtest/fcosetimpl_t.cpp index 153e0d0..b840958 100644 --- a/src/twtest/fcosetimpl_t.cpp +++ b/src/twtest/fcosetimpl_t.cpp @@ -155,3 +155,7 @@ void TestFCOSetImpl() } +void RegisterSuite_FCOSetImpl() +{ + RegisterTest("FCOSetImpl", "Basic", TestFCOSetImpl); +} diff --git a/src/twtest/fcospec_t.cpp b/src/twtest/fcospec_t.cpp index 251f4e5..86725d1 100644 --- a/src/twtest/fcospec_t.cpp +++ b/src/twtest/fcospec_t.cpp @@ -51,3 +51,8 @@ void TestFCOSpec() cout << "End\tTestFCOSpec" << endl; return; } + +void RegisterSuite_FCOSpec() +{ + RegisterTest("FCOSpec", "Basic", TestFCOSpec); +} diff --git a/src/twtest/fcospecattr_t.cpp b/src/twtest/fcospecattr_t.cpp index ffe9148..6ffc8fe 100644 --- a/src/twtest/fcospecattr_t.cpp +++ b/src/twtest/fcospecattr_t.cpp @@ -88,3 +88,8 @@ void TestFCOSpecAttr() pNew->Release(); pAttr->Release(); } + +void RegisterSuite_FCOSpecAttr() +{ + RegisterTest("FCOSpecAttr", "Basic", TestFCOSpecAttr); +} diff --git a/src/twtest/fcospechelper_t.cpp b/src/twtest/fcospechelper_t.cpp index 30ba8ce..5b86505 100644 --- a/src/twtest/fcospechelper_t.cpp +++ b/src/twtest/fcospechelper_t.cpp @@ -129,3 +129,8 @@ void TestFCOSpecHelper() delete pHelp1; delete pHelp2; } + +void RegisterSuite_FCOSpecHelper() +{ + RegisterTest("FCOSpecHelper", "Basic", TestFCOSpecHelper); +} diff --git a/src/twtest/fcospeclist_t.cpp b/src/twtest/fcospeclist_t.cpp index 8f06705..e5557c7 100644 --- a/src/twtest/fcospeclist_t.cpp +++ b/src/twtest/fcospeclist_t.cpp @@ -164,3 +164,7 @@ void TestFCOSpecList() return; } +void RegisterSuite_FCOSpecList() +{ + RegisterTest("FCOSpecList", "Basic", TestFCOSpecList); +} diff --git a/src/twtest/fcospecutil_t.cpp b/src/twtest/fcospecutil_t.cpp index 19979a7..4dbace8 100644 --- a/src/twtest/fcospecutil_t.cpp +++ b/src/twtest/fcospecutil_t.cpp @@ -80,3 +80,8 @@ void TestFcoSpecUtil() d.TraceDebug("Leaving..\n"); } + +void RegisterSuite_FcoSpecUtil() +{ + RegisterTest("FcoSpecUtil", "Basic", TestFcoSpecUtil); +} diff --git a/src/twtest/file_t.cpp b/src/twtest/file_t.cpp index 9700b83..1e55a96 100644 --- a/src/twtest/file_t.cpp +++ b/src/twtest/file_t.cpp @@ -58,3 +58,7 @@ void TestFile() TEST(testStream); } +void RegisterSuite_File() +{ + RegisterTest("File", "Basic", TestFile); +} diff --git a/src/twtest/fileheader_t.cpp b/src/twtest/fileheader_t.cpp index b2d0160..f4000b3 100644 --- a/src/twtest/fileheader_t.cpp +++ b/src/twtest/fileheader_t.cpp @@ -126,3 +126,8 @@ void TestFileHeader() TEST(memcmp(buf, "abc123", 6) == 0); } } + +void RegisterSuite_FileHeader() +{ + RegisterTest("FileHeader", "Basic", TestFileHeader); +} diff --git a/src/twtest/fileutil_t.cpp b/src/twtest/fileutil_t.cpp index b71a824..007c797 100644 --- a/src/twtest/fileutil_t.cpp +++ b/src/twtest/fileutil_t.cpp @@ -71,3 +71,7 @@ void TestFileUtil() unlink(source.c_str()); } +void RegisterSuite_FileUtil() +{ + RegisterTest("FileUtil", "Basic", TestFileUtil); +} diff --git a/src/twtest/fsdatasourceiter_t.cpp b/src/twtest/fsdatasourceiter_t.cpp index e462629..1917128 100644 --- a/src/twtest/fsdatasourceiter_t.cpp +++ b/src/twtest/fsdatasourceiter_t.cpp @@ -108,4 +108,9 @@ void TestFSDataSourceIter() PrintIter( iter, d ); } +void RegisterSuite_FSDataSourceIter() +{ + RegisterTest("FSDataSourceIter", "Basic", TestFSDataSourceIter); +} + diff --git a/src/twtest/fsobject_t.cpp b/src/twtest/fsobject_t.cpp index d486895..28d5fdd 100644 --- a/src/twtest/fsobject_t.cpp +++ b/src/twtest/fsobject_t.cpp @@ -32,9 +32,16 @@ // fsobject_t -- the file system object test driver #include "fs/stdfs.h" #include "fs/fsobject.h" +#include "test.h" void TestFSObject() { cDebug d("TestFSObject"); d.TraceError("Implement this!\n"); + skip("TestFSObject not implemented"); +} + +void RegisterSuite_FSObject() +{ + RegisterTest("FSObject", "Basic", TestFSObject); } diff --git a/src/twtest/fspropcalc_t.cpp b/src/twtest/fspropcalc_t.cpp index b98af3e..2699b2b 100644 --- a/src/twtest/fspropcalc_t.cpp +++ b/src/twtest/fspropcalc_t.cpp @@ -155,4 +155,8 @@ void TestGetSymLinkStr() TEST(arch.Length() == (int64)file.size()); } - +void RegisterSuite_FSPropCalc() +{ + RegisterTest("FSPropCalc", "Basic", TestFSPropCalc); + RegisterTest("FSPropCalc", "GetSymLinkStr", TestGetSymLinkStr); +} diff --git a/src/twtest/fspropdisplayer_t.cpp b/src/twtest/fspropdisplayer_t.cpp index a654df0..d1fdf82 100644 --- a/src/twtest/fspropdisplayer_t.cpp +++ b/src/twtest/fspropdisplayer_t.cpp @@ -133,3 +133,7 @@ void cTestFSPropDisplayer::Test() return; } +void RegisterSuite_FSPropDisplayer() +{ + RegisterTest("FSPropDisplayer", "Basic", TestFSPropDisplayer); +} diff --git a/src/twtest/fspropset_t.cpp b/src/twtest/fspropset_t.cpp index 269b447..89914d6 100644 --- a/src/twtest/fspropset_t.cpp +++ b/src/twtest/fspropset_t.cpp @@ -92,3 +92,8 @@ void TestFSPropSet() return; } + +void RegisterSuite_FSPropSet() +{ + RegisterTest("FSPropSet", "Basic", TestFSPropSet); +} diff --git a/src/twtest/fsspec_t.cpp b/src/twtest/fsspec_t.cpp index c115988..aca91ca 100644 --- a/src/twtest/fsspec_t.cpp +++ b/src/twtest/fsspec_t.cpp @@ -102,3 +102,7 @@ void TestFCOSpecImpl() pSpec->Release(); } +void RegisterSuite_FCOSpecImpl() +{ + RegisterTest("FCOSpecImpl", "Basic", TestFCOSpecImpl); +} diff --git a/src/twtest/genre_t.cpp b/src/twtest/genre_t.cpp index 2f425d8..e9f3395 100644 --- a/src/twtest/genre_t.cpp +++ b/src/twtest/genre_t.cpp @@ -33,31 +33,30 @@ // genre_t.cpp // -#include - #include "fco/stdfco.h" #include "fco/genreswitcher.h" #include "twtest/test.h" #include "fs/fs.h" -#include "fs/fsfactory.h" - -void TestGenreSwitcher() +void TestGenre() { - cDebug d("TestGenreSwitcher"); + cDebug d("TestGenre"); d.TraceDebug("Entering...\n"); - cGenreSwitcher* genreSwitcher = cGenreSwitcher::GetInstance(); + TEST(cGenreSwitcher::GetInstance()->StringToGenre(cGenreSwitcher::GetInstance()->GenreToString(cFS::GenreID())) == cFS::GenreID()); - TEST(genreSwitcher->CurrentGenre() == cFS::GenreID()); - - // can't switch to invalid genre - //genreSwitcher->SelectGenre(cGenre::GENRE_INVALID); - //TEST(genreSwitcher->CurrentGenre() == cGenre::GENRE_INVALID); + //TODO: GenreToString() dies w/ GENRE_INVALID. Figure out if this should be changed. + // + //TEST(cGenreSwitcher::GetInstance()->StringToGenre(cGenreSwitcher::GetInstance()->GenreToString(cGenre::GENRE_INVALID)) == cGenre::GENRE_INVALID); - genreSwitcher->SelectGenre(cFS::GenreID()); - TEST(genreSwitcher->CurrentGenre() == cFS::GenreID()); - TEST(typeid(*iTWFactory::GetInstance()) == typeid(cFSFactory)); + + TEST(cGenreSwitcher::GetInstance()->StringToGenre(_T("fs")) == cFS::GenreID()); + TEST(cGenreSwitcher::GetInstance()->StringToGenre(_T("none of the above")) == cGenre::GENRE_INVALID); d.TraceDebug("All tests passed.\n"); } + +void RegisterSuite_Genre() +{ + RegisterTest("Genre", "Basic", TestGenre); +} diff --git a/src/twtest/genrespeclist_t.cpp b/src/twtest/genrespeclist_t.cpp index 9109d24..8b446c0 100644 --- a/src/twtest/genrespeclist_t.cpp +++ b/src/twtest/genrespeclist_t.cpp @@ -91,3 +91,12 @@ void TestGenreSpecList() d.TraceDebug("All tests passed.\n"); } + +void RegisterSuite_GenreSpecList() +{ + RegisterTest("GenreSpecList", "Basic", TestGenreSpecList); +} + + + + diff --git a/src/twtest/genreswitcher_t.cpp b/src/twtest/genreswitcher_t.cpp index d378b1e..6fbd8eb 100644 --- a/src/twtest/genreswitcher_t.cpp +++ b/src/twtest/genreswitcher_t.cpp @@ -33,25 +33,36 @@ // genreswitcher_t.h // +#include + #include "fco/stdfco.h" #include "fco/genreswitcher.h" #include "twtest/test.h" #include "fs/fs.h" -void TestGenre() +#include "fs/fsfactory.h" + +void TestGenreSwitcher() { - cDebug d("TestGenre"); + cDebug d("TestGenreSwitcher"); d.TraceDebug("Entering...\n"); - TEST(cGenreSwitcher::GetInstance()->StringToGenre(cGenreSwitcher::GetInstance()->GenreToString(cFS::GenreID())) == cFS::GenreID()); - - //TODO: GenreToString() dies w/ GENRE_INVALID. Figure out if this should be changed. - // - //TEST(cGenreSwitcher::GetInstance()->StringToGenre(cGenreSwitcher::GetInstance()->GenreToString(cGenre::GENRE_INVALID)) == cGenre::GENRE_INVALID); - + cGenreSwitcher* genreSwitcher = cGenreSwitcher::GetInstance(); - TEST(cGenreSwitcher::GetInstance()->StringToGenre(_T("fs")) == cFS::GenreID()); - TEST(cGenreSwitcher::GetInstance()->StringToGenre(_T("none of the above")) == cGenre::GENRE_INVALID); + TEST(genreSwitcher->CurrentGenre() == cFS::GenreID()); + + // can't switch to invalid genre + //genreSwitcher->SelectGenre(cGenre::GENRE_INVALID); + //TEST(genreSwitcher->CurrentGenre() == cGenre::GENRE_INVALID); + + genreSwitcher->SelectGenre(cFS::GenreID()); + TEST(genreSwitcher->CurrentGenre() == cFS::GenreID()); + TEST(typeid(*iTWFactory::GetInstance()) == typeid(cFSFactory)); d.TraceDebug("All tests passed.\n"); } + +void RegisterSuite_GenreSwitcher() +{ + RegisterTest("GenreSwitcher", "Basic", TestGenreSwitcher); +} diff --git a/src/twtest/growheap_t.cpp b/src/twtest/growheap_t.cpp index 8fb6f99..61eecd2 100644 --- a/src/twtest/growheap_t.cpp +++ b/src/twtest/growheap_t.cpp @@ -97,3 +97,7 @@ void TestGrowHeap() TEST( gh.TotalMemUsage() == 0 ); } +void RegisterSuite_GrowHeap() +{ + RegisterTest("GrowHeap", "Basic", TestGrowHeap); +} diff --git a/src/twtest/hashtable_t.cpp b/src/twtest/hashtable_t.cpp index 96ea4d8..67b430e 100644 --- a/src/twtest/hashtable_t.cpp +++ b/src/twtest/hashtable_t.cpp @@ -43,15 +43,6 @@ using namespace std; -void HashTest1(); -void HashTest2(); - -void TestHashTable(void) -{ - HashTest1(); - HashTest2(); -} - void HashTest1() { //Test the Hash table with Key = TSTRING @@ -218,3 +209,9 @@ void HashTest2() d.TraceDebug("PASSED!\n"); } + +void RegisterSuite_HashTable() +{ + RegisterTest("HashTable", "Basic 1", HashTest1); + RegisterTest("HashTable", "Basic 2", HashTest2); +} diff --git a/src/twtest/hierdatabase_t.cpp b/src/twtest/hierdatabase_t.cpp index e18a8cf..4b87202 100644 --- a/src/twtest/hierdatabase_t.cpp +++ b/src/twtest/hierdatabase_t.cpp @@ -206,3 +206,8 @@ void TestHierDatabaseBasic() #endif } +void RegisterSuite_HierDatabase() +{ + RegisterTest("HierDatabase", "Basic", TestHierDatabaseBasic); +} + diff --git a/src/twtest/keyfile_t.cpp b/src/twtest/keyfile_t.cpp index 656dc05..cae960a 100644 --- a/src/twtest/keyfile_t.cpp +++ b/src/twtest/keyfile_t.cpp @@ -134,3 +134,7 @@ void TestKeyFile() return; } +void RegisterSuite_KeyFile() +{ + RegisterTest("KeyFile", "Basic", TestKeyFile); +} diff --git a/src/twtest/platform_t.cpp b/src/twtest/platform_t.cpp index 49cae44..b4ed007 100644 --- a/src/twtest/platform_t.cpp +++ b/src/twtest/platform_t.cpp @@ -204,6 +204,7 @@ void TestSizes() { cDebug d("TestSizes"); d.TraceError("Fix this!\n"); + skip("TODO: TestSizes needs work"); /* TEST( CanBeRepresentedAs( char(), char() ) ); TEST( CanBeRepresentedAs( char(), unsigned char() ) ); @@ -234,3 +235,9 @@ bool CanBeRepresentedAs( E e, T t ) return fReturn; } + +void RegisterSuite_Platform() +{ + RegisterTest("Platform", "Alignment", TestAlignment); + RegisterTest("Platform", "Sizes", TestSizes); +} diff --git a/src/twtest/policyparser_t.cpp b/src/twtest/policyparser_t.cpp index 97a6c35..6070e2d 100644 --- a/src/twtest/policyparser_t.cpp +++ b/src/twtest/policyparser_t.cpp @@ -101,6 +101,9 @@ void TestPolicyParser() cDebug d("TestPolicyParser()"); test_policy_file("pol.txt"); + + TCERR << "TestPolicyParser: Parser needs work to be able to test more than one policy" << std::endl; + // test_policy_file("directives.txt"); //fails unless you substitute your hostname for 'your_host' in this file // TODO: test currently segfaults if you create more than one policy parser in a process. (Not a real world scenario). @@ -110,4 +113,7 @@ void TestPolicyParser() test_policy_file("polruleattr.txt"); */ } - +void RegisterSuite_PolicyParser() +{ + RegisterTest("PolicyParser", "Basic", TestPolicyParser); +} diff --git a/src/twtest/refcountobj_t.cpp b/src/twtest/refcountobj_t.cpp index 68468c0..fb870ac 100644 --- a/src/twtest/refcountobj_t.cpp +++ b/src/twtest/refcountobj_t.cpp @@ -33,6 +33,7 @@ #include "core/stdcore.h" #include "core/refcountobj.h" #include "core/debug.h" +#include "test.h" class cRefCountTestObj : public cRefCountObj { @@ -166,3 +167,7 @@ void TestRefCountObj() return; } +void RegisterSuite_RefCountObj() +{ + RegisterTest("RefCountObj", "Basic", TestRefCountObj); +} diff --git a/src/twtest/resources_t.cpp b/src/twtest/resources_t.cpp index 52b37ec..b2533e3 100644 --- a/src/twtest/resources_t.cpp +++ b/src/twtest/resources_t.cpp @@ -95,6 +95,9 @@ void TestResources() } - +void RegisterSuite_Resources() +{ + RegisterTest("Resources", "Basic", TestResources); +} diff --git a/src/twtest/serializer_t.cpp b/src/twtest/serializer_t.cpp index ab4cd21..2244f05 100644 --- a/src/twtest/serializer_t.cpp +++ b/src/twtest/serializer_t.cpp @@ -38,6 +38,7 @@ #include "core/stdcore.h" #include "core/serializer.h" #include "core/serializable.h" +#include "test.h" // The reading and writing functionality of the serializer is tested in // serializerimpl_t.cpp, so there's very little to be done here. @@ -71,3 +72,8 @@ void TestSerializer() { cSerTestObject test_obj; } + +void RegisterSuite_Serializer() +{ + RegisterTest("Serializer", "Basic", TestSerializer); +} diff --git a/src/twtest/serializerimpl_t.cpp b/src/twtest/serializerimpl_t.cpp index cf69777..7762abf 100644 --- a/src/twtest/serializerimpl_t.cpp +++ b/src/twtest/serializerimpl_t.cpp @@ -178,3 +178,7 @@ void TestSerializerImpl() return; } +void RegisterSuite_SerializerImpl() +{ + RegisterTest("SerializerImpl", "Basic", TestSerializerImpl); +} diff --git a/src/twtest/signature_t.cpp b/src/twtest/signature_t.cpp index 55ee530..82b4b7d 100644 --- a/src/twtest/signature_t.cpp +++ b/src/twtest/signature_t.cpp @@ -361,3 +361,7 @@ void TestSignature() return; } +void RegisterSuite_Signature() +{ + RegisterTest("Signature", "Basic", TestSignature); +} diff --git a/src/twtest/srefcountobj_t.cpp b/src/twtest/srefcountobj_t.cpp index e12a486..9f0b118 100644 --- a/src/twtest/srefcountobj_t.cpp +++ b/src/twtest/srefcountobj_t.cpp @@ -144,3 +144,7 @@ void TestSerRefCountObj() return; } +void RegisterSuite_SerRefCountObj() +{ + RegisterTest("SerRefCountObj", "Basic", TestSerRefCountObj); +} diff --git a/src/twtest/stringencoder_t.cpp b/src/twtest/stringencoder_t.cpp index 77fea63..d0b7cf3 100644 --- a/src/twtest/stringencoder_t.cpp +++ b/src/twtest/stringencoder_t.cpp @@ -93,3 +93,7 @@ void OutputString( TSTRING& str ) TEST( str == qe.Unencode(qe.Encode(str)) ); } +void RegisterSuite_StringEncoder() +{ + RegisterTest("StringEncoder", "Basic", TestStringEncoder); +} diff --git a/src/twtest/stringutil_t.h b/src/twtest/stringutil_t.h index 4ed2875..70117f0 100644 --- a/src/twtest/stringutil_t.h +++ b/src/twtest/stringutil_t.h @@ -172,3 +172,8 @@ void TestStringUtil() #endif//__STRINGUTIL_T_H + +void RegisterSuite_StringUtil() +{ + RegisterTest("StringUtil", "Basic", TestStringUtil); +} diff --git a/src/twtest/tasktimer_t.cpp b/src/twtest/tasktimer_t.cpp index c501261..383021b 100644 --- a/src/twtest/tasktimer_t.cpp +++ b/src/twtest/tasktimer_t.cpp @@ -31,11 +31,17 @@ // // tasktimer_t -- test driver for cTaskTimer #include "core/stdcore.h" +#include "test.h" void TestTaskTimer() { cDebug d("TestTaskTimer"); d.TraceError("Implement this!\n"); + skip("TestTaskTimer unimplemented"); } +void RegisterSuite_TaskTimer() +{ + RegisterTest("TaskTimer", "Basic", TestTaskTimer); +} diff --git a/src/twtest/tchar_t.cpp b/src/twtest/tchar_t.cpp index 9bcc5d0..702bd79 100644 --- a/src/twtest/tchar_t.cpp +++ b/src/twtest/tchar_t.cpp @@ -133,3 +133,8 @@ void test_wist(const TSTRING& input, cDebug& d) d.TraceDetail("%s \n", parse.c_str() ); } +void RegisterSuite_TCHAR() +{ + RegisterTest("TCHAR", "Basic", TestTCHAR); +} + diff --git a/src/twtest/test.cpp b/src/twtest/test.cpp index fd6b2b9..69cca93 100644 --- a/src/twtest/test.cpp +++ b/src/twtest/test.cpp @@ -64,197 +64,142 @@ #include #include -// the test routines -void TestFCOName(); -void TestFCOTest(); -void TestFCOSetImpl(); -void TestFCOSpec(); -void TestFCOPropVector(); -void TestFileHeader(); -void TestFile(); -void TestFSPropSet(); -void TestFCOSpecImpl(); -void TestFSObject(); -void TestFSPropCalc(); -void TestFCOPropImpl(); -void TestFCOCompare(); -//void TestTripwire(); -void TestWin32FSServices(); -void TestFCOSpecList(); -void TestFCOReport(); -void TestArchive(); -void TestSerializer(); -void TestSerializerImpl(); -void TestRefCountObj(); -void TestSignature(); -void TestSerRefCountObj(); -void TestUnixFSServices(); -void TestError(); -void TestDebug(); -void TestFcoSpecUtil(); -void TestTypes(); -void TestTCHAR(); -void TestErrorBucketImpl(); -void TestHashTable(); -void TestTextReportViewer(); -void TestFCONameTbl(); -void TestConfigFile(); -void TestResources(); -void TestGetSymLinkStr(); -void TestPolicyParser(); - -void TestFCOSpecHelper(); -void TestCrypto(); -void TestCryptoArchive(); -void TestFCOSpecAttr(); -void TestCmdLineParser(); -void TestTaskTimer(); -void TestKeyFile(); -void TestTWUtil(); -void TestFSPropDisplayer(); -void TestFSPropDisplayer(); -void TestGenre(); -void TestFSDataSourceIter(); -void TestGenerateDb(); -void TestHierDatabaseBasic(); -void TestGenreSwitcher(); -void TestDbDataSourceBasic(); -void TestGenreSpecList(); -void TestIntegrityCheck(); -void TestFCODatabaseFile(); -void TestWchar16(); -void TestStringEncoder(); - -void TestGrowHeap(); -void TestPlatform(); -void TestBlockFile(); -void TestBlockRecordArray(); -void TestTWLocale(); -void TestFileUtil(); -void TestFCONameTranslator(); -void TestCodeConverter(); - -void TestCharToHex(); -void TestHexToChar(); -void TestStringToHex(); -void TestHexToString(); -//void TestUnconvertable(); -//void TestUnprintable(); -void TestQuoteAndBackSlash(); -void TestDisplayEncoderBasic(); -void TestCharUtilBasic(); -void TestConfigFile2(); -void TestUserNotifyStdout(); +// Known test suites +void RegisterSuite_Archive(); +void RegisterSuite_BlockFile(); +void RegisterSuite_BlockRecordArray(); +void RegisterSuite_CharUtil(); +void RegisterSuite_CmdLineParser(); +void RegisterSuite_CodeConvert(); +void RegisterSuite_ConfigFile(); +void RegisterSuite_CryptoArchive(); +void RegisterSuite_Crypto(); +void RegisterSuite_DbDataSource(); +void RegisterSuite_Debug(); +void RegisterSuite_DisplayEncoder(); +void RegisterSuite_Error(); +void RegisterSuite_ErrorBucketImpl(); +void RegisterSuite_FCOCompare(); +void RegisterSuite_FCODatabaseFile(); +void RegisterSuite_FCOName(); +void RegisterSuite_FCONameTbl(); +void RegisterSuite_FCONameTranslator(); +void RegisterSuite_FCOPropImpl(); +void RegisterSuite_FCOPropVector(); +void RegisterSuite_FCOReport(); +void RegisterSuite_FCOSetImpl(); +void RegisterSuite_FCOSpec(); +void RegisterSuite_FCOSpecAttr(); +void RegisterSuite_FCOSpecHelper(); +void RegisterSuite_FCOSpecList(); +void RegisterSuite_FcoSpecUtil(); +void RegisterSuite_File(); +void RegisterSuite_FileHeader(); +void RegisterSuite_FileUtil(); +void RegisterSuite_FSDataSourceIter(); +void RegisterSuite_FSObject(); +void RegisterSuite_FSPropCalc(); +void RegisterSuite_FSPropDisplayer(); +void RegisterSuite_FSPropSet(); +void RegisterSuite_FCOSpecImpl(); +void RegisterSuite_GenreSwitcher(); +void RegisterSuite_GenreSpecList(); +void RegisterSuite_Error(); +void RegisterSuite_GrowHeap(); +void RegisterSuite_HashTable(); +void RegisterSuite_HierDatabase(); +void RegisterSuite_KeyFile(); +void RegisterSuite_Platform(); +void RegisterSuite_PolicyParser(); +void RegisterSuite_RefCountObj(); +void RegisterSuite_Resources(); +void RegisterSuite_Serializer(); +void RegisterSuite_SerializerImpl(); +void RegisterSuite_Signature(); +void RegisterSuite_SerRefCountObj(); +void RegisterSuite_StringEncoder(); +void RegisterSuite_StringUtil(); +void RegisterSuite_TaskTimer(); +void RegisterSuite_TCHAR(); +void RegisterSuite_TextReportViewer(); +void RegisterSuite_TWLocale(); +void RegisterSuite_TWUtil(); +void RegisterSuite_Types(); +void RegisterSuite_UnixFSServices(); +void RegisterSuite_UserNotifyStdout(); +void RegisterSuite_Wchar16(); /// This is easier than all the (cpp) files and declarations #include "stringutil_t.h" void Usage() { - TCERR << _T("Usage: test {all | testid [testid ...]}\n") + TCERR << _T("Usage: test {all | list | testid [testid ...]}\n") _T("\n") - _T("Ex: test 1 2 3 12\n") - _T("(runs test id's 1, 2, 3, and 12)\n\n"); + _T("Ex: test foo bar/baz\n") + _T("(runs suite foo and test bar/baz)\n\n"); } -const int MAX_TEST_ID = 88; - static int ran_count = 0; static int failed_count = 0; +static int skipped_count = 0; +static int macro_count = 0; + static std::vector error_strings; +static std::vector skipped_strings; -static void Test(int testID) +class skip_exception : public std::runtime_error { - TCERR << std::endl << "=== Running test ID #" << testID << " ===" << std::endl; - - bool ran = true; +public: + skip_exception(const std::string& reason) : std::runtime_error(reason) {} +}; - try { - - switch (testID) +void skip(const std::string& reason) +{ + throw skip_exception(reason); +} + +void CountMacro() +{ + macro_count++; + TCERR << "*** Incrementing macro count, value is now" << macro_count << std::endl;; +} + +///////////////////////// + +static TestMap tests; + +void RegisterTest(const std::string& suite, const std::string testName, TestPtr testPtr ) +{ + tests[suite][testName] = testPtr; +} + + +static void RunTest(const std::string& suiteName, const std::string& testName, TestPtr testPtr) +{ + try + { + if (testPtr) { - case 1: TestArchive(); break; - case 2: TestCmdLineParser(); break; - case 3: TestCrypto(); break; - case 4: TestCryptoArchive(); break; - case 5: TestDebug(); break; - case 6: TestError(); break; - case 7: TestErrorBucketImpl(); break; - case 8: TestFCOCompare(); break; - case 9: TestUserNotifyStdout(); break; - - case 12: TestFCOName(); break; - case 13: TestFCONameTbl(); break; - case 14: TestFCOPropVector(); break; - case 15: TestFCOPropImpl(); break; - case 16: TestFCOReport(); break; - case 17: TestGetSymLinkStr(); break; - case 18: TestFCOSetImpl(); break; - case 19: TestFCOSpec(); break; - case 20: TestFCOSpecAttr(); break; - case 21: TestFCOSpecHelper(); break; - case 22: TestFCOSpecList(); break; - case 23: TestFcoSpecUtil(); break; - case 24: TestFileHeader(); break; - case 25: TestFile(); break; - case 26: TestFSPropSet(); break; - case 27: TestFSPropCalc(); break; - case 28: TestFCOSpecImpl(); break; - case 29: TestFSObject(); break; - case 30: TestSerializer(); break; - case 31: TestRefCountObj(); break; - case 32: TestSerializerImpl(); break; - case 33: TestResources(); break; - case 34: TestSignature(); break; - case 35: TestTaskTimer(); break; - //case 36: TestTripwire(); break; - case 37: TestTextReportViewer(); break; - case 39: TestSerRefCountObj(); break; - case 40: TestError(); break; - case 41: TestFCODatabaseFile(); break; - case 42: TestHashTable(); break; - case 43: TestTCHAR(); break; - case 44: TestTypes(); break; - case 45: TestUnixFSServices(); break; - case 46: TestConfigFile(); break; - case 47: TestPolicyParser(); break; - case 48: TestKeyFile(); break; - case 49: TestTWUtil(); break; - case 50: TestFSPropDisplayer(); break; - case 52: TestGenre(); break; - case 53: TestFSDataSourceIter(); break; - //case 54: TestGenerateDb(); break; - case 55: TestHierDatabaseBasic(); break; - case 56: TestGenreSwitcher(); break; - case 57: TestDbDataSourceBasic(); break; - case 58: TestGenreSpecList(); break; - //case 59: TestIntegrityCheck(); break; - - case 65: TestWchar16(); break; - case 66: TestStringEncoder(); break; - - case 69: TestGrowHeap(); break; - case 70: TestPlatform(); break; - case 71: TestBlockFile(); break; - case 72: TestBlockRecordArray(); break; - case 74: TestFileUtil(); break; - case 75: TestTWLocale(); break; - case 76: TestFCONameTranslator(); break; - case 77: TestStringUtil(); break; - case 78: TestCodeConverter(); break; - - case 79: TestCharToHex(); break; - case 80: TestHexToChar(); break; - case 81: TestStringToHex(); break; - case 82: TestHexToString(); break; - // case 83: TestUnconvertable(); break; - // case 84: TestUnprintable(); break; - case 85: TestQuoteAndBackSlash(); break; - case 86: TestDisplayEncoderBasic(); break; - case 87: TestCharUtilBasic(); break; - case 88: TestConfigFile2(); break; - default: ran = false; break; + ran_count++; + int pre_count = macro_count; + testPtr(); + if (macro_count > pre_count) + TCERR << "PASSED" << std::endl; + else + skip("Test did not make any TEST assertions"); } + return; + } + catch (skip_exception& e) + { + TCERR << "SKIPPED: " << e.what() << std::endl; + + std::stringstream sstr; + sstr << "Test " << suiteName << "/" << testName << ": " << e.what(); + skipped_strings.push_back(sstr.str()); + + skipped_count++; } catch (eError& error) { @@ -262,7 +207,7 @@ static void Test(int testID) cTWUtil::PrintErrorMsg(error); std::stringstream sstr; - sstr << "Test " << testID << ": " << error.GetMsg(); + sstr << "Test " << suiteName << "/" << testName << ": " << error.GetMsg(); error_strings.push_back(sstr.str()); failed_count++; @@ -271,7 +216,7 @@ static void Test(int testID) TCERR << "FAILED: " << e.what() << std::endl; std::stringstream sstr; - sstr << "Test " << testID << ": " << e.what(); + sstr << "Test " << suiteName << "/" << testName << ": " << e.what(); error_strings.push_back(sstr.str()); failed_count++; @@ -280,21 +225,134 @@ static void Test(int testID) TCERR << "FAILED: " << std::endl; std::stringstream sstr; - sstr << "Test " << testID << ": "; + sstr << "Test " << suiteName << "/" << testName << ": "; error_strings.push_back(sstr.str()); - - failed_count++; } - - if(ran) +} + + +static void RunTestSuite(const std::string& suiteName, SuiteMap suite) +{ + SuiteMap::const_iterator itr; + for( itr = suite.begin(); itr != suite.end(); ++itr) { - ran_count++; - TCERR << std::endl << "=== test ID #" << testID << " completed ===" << std::endl; + TCERR << "----- Running test: " << suiteName << "/" << itr->first << " -----" << std::endl << std::endl; + RunTest(suiteName, itr->first, itr->second); + TCERR << std::endl << "----- Finished test: " << suiteName << "/" << itr->first << " -----" << std::endl; + } +} + +static void RunAllTests() +{ + TestMap::const_iterator itr; + for( itr = tests.begin(); itr != tests.end(); ++itr) + { + TCERR << std::endl << "===== Starting test suite: " << itr->first << " =====" << std::endl; + RunTestSuite(itr->first, itr->second); + TCERR << "===== Finished test suite: " << itr->first << " =====" << std::endl; + } +} + +static void ListTests() +{ + TestMap::const_iterator itr; + for( itr = tests.begin(); itr != tests.end(); ++itr) + { + std::string suiteName = itr->first; + SuiteMap suite = itr->second; + + TCERR << suiteName << std::endl; + SuiteMap::const_iterator itr; + for( itr = suite.begin(); itr != suite.end(); ++itr) + { + TCERR << " " << suiteName << "/" << itr->first << std::endl; + } + } +} + +static void RunTest(const std::string& to_run) +{ + std::string::size_type pos = to_run.find_first_of("/"); + if(pos == std::string::npos) + { + RunTestSuite(to_run, tests[to_run]); } else - TCERR << std::endl << "=== test ID #" << testID << " currently unused ===" << std::endl; + { + std::string suite = to_run.substr(0, pos); + std::string testName = to_run.substr(pos+1); + RunTest(suite, testName, tests[suite][testName]); + } } +static void RegisterSuites() +{ + RegisterSuite_Archive(); + RegisterSuite_BlockFile(); + RegisterSuite_BlockRecordArray(); + RegisterSuite_CharUtil(); + RegisterSuite_CmdLineParser(); + RegisterSuite_CodeConvert(); + RegisterSuite_ConfigFile(); + RegisterSuite_CryptoArchive(); + RegisterSuite_Crypto(); + RegisterSuite_DbDataSource(); + RegisterSuite_Debug(); + RegisterSuite_DisplayEncoder(); + RegisterSuite_Error(); + RegisterSuite_ErrorBucketImpl(); + RegisterSuite_FCOCompare(); + RegisterSuite_FCODatabaseFile(); + RegisterSuite_FCOName(); + RegisterSuite_FCONameTbl(); + RegisterSuite_FCONameTranslator(); + RegisterSuite_FCOPropImpl(); + RegisterSuite_FCOPropVector(); + RegisterSuite_FCOReport(); + RegisterSuite_FCOSetImpl(); + RegisterSuite_FCOSpec(); + RegisterSuite_FCOSpecAttr(); + RegisterSuite_FCOSpecHelper(); + RegisterSuite_FCOSpecList(); + RegisterSuite_FcoSpecUtil(); + RegisterSuite_File(); + RegisterSuite_FileHeader(); + RegisterSuite_FileUtil(); + RegisterSuite_FSDataSourceIter(); + RegisterSuite_FSObject(); + RegisterSuite_FSPropCalc(); + RegisterSuite_FSPropDisplayer(); + RegisterSuite_FSPropSet(); + RegisterSuite_FCOSpecImpl(); + RegisterSuite_GenreSwitcher(); + RegisterSuite_GenreSpecList(); + RegisterSuite_Error(); + RegisterSuite_GrowHeap(); + RegisterSuite_HashTable(); + RegisterSuite_HierDatabase(); + RegisterSuite_KeyFile(); + RegisterSuite_Platform(); + RegisterSuite_PolicyParser(); + RegisterSuite_RefCountObj(); + RegisterSuite_Resources(); + RegisterSuite_Serializer(); + RegisterSuite_SerializerImpl(); + RegisterSuite_Signature(); + RegisterSuite_SerRefCountObj(); + RegisterSuite_StringEncoder(); + RegisterSuite_StringUtil(); + RegisterSuite_TaskTimer(); + RegisterSuite_TCHAR(); + RegisterSuite_TextReportViewer(); + RegisterSuite_TWLocale(); + RegisterSuite_TWUtil(); + RegisterSuite_Types(); + RegisterSuite_UnixFSServices(); + RegisterSuite_UserNotifyStdout(); + RegisterSuite_Wchar16(); +} + + std::string TwTestDir() { static std::string dir; @@ -358,17 +416,21 @@ void tw_unexpected_handler() int _tmain(int argc, TCHAR** argv) { +#ifdef _DEBUG std::cout << "Test: Init" << std::endl; + std::cout << "Test: Setup" << std::endl; + std::cout << "Test: argc - " << argc << std::endl; + std::cout << "Test: *argv - " << argv[0] << std::endl; +#endif - try + try { - std::cout << "Test: Setup" << std::endl; - std::cout << "Test: argc - " << argc << std::endl; - std::cout << "Test: *argv - " << argv[0] << std::endl; - EXCEPTION_NAMESPACE set_terminate(tw_terminate_handler); EXCEPTION_NAMESPACE set_unexpected(tw_unexpected_handler); + if (argc < 2) + Usage(); + cTWInit twInit; twInit.Init( argv[0] ); @@ -377,20 +439,24 @@ int _tmain(int argc, TCHAR** argv) //cDebug::SetDebugLevel(cDebug::D_NEVER); cDebug::SetDebugLevel(cDebug::D_DETAIL); //cDebug::SetDebugLevel(cDebug::D_DEBUG); - - int i; - if (argc < 2) - Usage(); - else if (_tcsicmp(argv[1], _T("all")) == 0) - // run all the tests - for (i = 1; i <= MAX_TEST_ID; ++i) - Test(i); + RegisterSuites(); + + if (_tcsicmp(argv[1], _T("all")) == 0) + { + RunAllTests(); + } + else if(_tcsicmp(argv[1], _T("list")) == 0) + { + ListTests(); + } else - for (i = 1; i < argc; ++i) - Test(_ttoi(argv[i])); // Note: if atoi returns 0, Test() will handle it fine. - - } + { + for (int i = 1; i < argc; ++i) + RunTest(argv[i]); + } + + } catch (eError& error) { cTWUtil::PrintErrorMsg(error); @@ -404,16 +470,30 @@ int _tmain(int argc, TCHAR** argv) return 1; } - // make sure all the refrence counted objects have been destroyed + // make sure all the reference counted objects have been destroyed // this test always fails because of the static cFCONameTbl //TEST(cRefCountObj::AllRefCountObjDestoryed() == true); - std::cout << std::endl << "Ran " << ran_count << " unit tests with " << failed_count << " failures." << std::endl; + std::cout << std::endl << "Ran " << ran_count << " unit tests with " << failed_count << " failures, " << skipped_count << " skipped." << std::endl; - std::vector::iterator itr; - for (itr = error_strings.begin(); itr != error_strings.end(); ++itr) + if (failed_count) { - std::cout << "\t" << *itr << std::endl; + std::cout << std::endl << "Failures: " << std::endl; + std::vector::iterator itr; + for (itr = error_strings.begin(); itr != error_strings.end(); ++itr) + { + std::cout << "\t" << *itr << std::endl; + } + } + + if (skipped_count) + { + std::cout << std::endl << "Skipped: " << std::endl; + std::vector::iterator itr; + for (itr = skipped_strings.begin(); itr != skipped_strings.end(); ++itr) + { + std::cout << "\t" << *itr << std::endl; + } } std::cout << std::endl; diff --git a/src/twtest/test.h b/src/twtest/test.h index 13c8db9..90351bb 100644 --- a/src/twtest/test.h +++ b/src/twtest/test.h @@ -66,9 +66,13 @@ public: TSS_EndPackage( cTest ) +void CountMacro(); + /////////////////////////////////////////////////////////////////////////////// -// TEST() -- Works like ASSERT() but it also breaks during release mode -#define TEST(exp) if (!(exp)) \ +// TEST() -- throw a std::runtime error if test condition is false. +// +#define TEST(exp) CountMacro(); \ + if (!(exp)) \ { \ std::cerr<<"TEST(" << #exp << ") failure, file " << __FILE__ << " line " << __LINE__ << std::endl; \ throw std::runtime_error(#exp); \ @@ -79,5 +83,14 @@ TSS_EndPackage( cTest ) std::string TwTestDir(); std::string TwTestPath(const std::string& child); +typedef void (*TestPtr)(); +typedef std::map< std::string, TestPtr > SuiteMap; +typedef std::map< std::string, SuiteMap > TestMap; + +void RegisterTest(const std::string& suite, const std::string testName, TestPtr testPtr ); + +void skip(const std::string& reason); + + #endif // __TEST_H diff --git a/src/twtest/textreportviewer_t.cpp b/src/twtest/textreportviewer_t.cpp index c5ed3e7..7616862 100644 --- a/src/twtest/textreportviewer_t.cpp +++ b/src/twtest/textreportviewer_t.cpp @@ -127,7 +127,7 @@ static void TraceReport(const cFCOReport& r, cDebug& d) void TestTextReportViewer() { - TCERR << std::endl << "TestTextReportViewer needs to be cleaned up & fixed, currently disabled" << std::endl; + skip("TestTextReportViewer needs to be cleaned up & fixed, currently disabled"); #if 0 cFCOReport report; @@ -476,3 +476,7 @@ void MakeDir( const TCHAR* const lpszDirName ) //#endif //FIXED_TRV_TEST_SUITE +void RegisterSuite_TextReportViewer() +{ + RegisterTest("TextReportViewer", "Basic", TestTextReportViewer); +} diff --git a/src/twtest/twlocale_t.cpp b/src/twtest/twlocale_t.cpp index 3bb4df0..289ba28 100644 --- a/src/twtest/twlocale_t.cpp +++ b/src/twtest/twlocale_t.cpp @@ -40,6 +40,7 @@ #include "core/stdcore.h" #include "core/debug.h" #include "core/twlocale.h" +#include "test.h" void TestAtoi(); void TestItoa(); @@ -56,6 +57,8 @@ void TestHex(); void TestTWLocale() { + skip("TWLocale tests are ifdef'd out, need to revisit them"); + #ifdef DOESNTWORK TestHex(); TestAtoi(); @@ -225,3 +228,8 @@ void TestHex() } #endif//DOESNTWORK +void RegisterSuite_TWLocale() +{ + RegisterTest("TWLocale", "Basic", TestTWLocale); +} + diff --git a/src/twtest/twutil_t.cpp b/src/twtest/twutil_t.cpp index 1f0a9e1..93e270b 100644 --- a/src/twtest/twutil_t.cpp +++ b/src/twtest/twutil_t.cpp @@ -108,3 +108,8 @@ std::string WideToNarrow( const TSTRING& strWide ) return strWide; } +void RegisterSuite_TWUtil() +{ + RegisterTest("TWUtil", "Basic", TestTWUtil); +} + diff --git a/src/twtest/types_t.cpp b/src/twtest/types_t.cpp index de1d18e..1b4fe67 100644 --- a/src/twtest/types_t.cpp +++ b/src/twtest/types_t.cpp @@ -50,3 +50,8 @@ void TestTypes() TEST(sizeof(float32) == 4); TEST(sizeof(float64) == 8); } + +void RegisterSuite_Types() +{ + RegisterTest("Types", "Basic", TestTypes); +} diff --git a/src/twtest/unixfsservices_t.cpp b/src/twtest/unixfsservices_t.cpp index 2d00329..45acdbb 100644 --- a/src/twtest/unixfsservices_t.cpp +++ b/src/twtest/unixfsservices_t.cpp @@ -158,7 +158,10 @@ void TestUnixFSServices() TEST( pFSServices->FileDelete( newtestfile ) ); } - +void RegisterSuite_UnixFSServices() +{ + RegisterTest("UnixFSServices", "Basic", TestUnixFSServices); +} diff --git a/src/twtest/usernotifystdout_t.cpp b/src/twtest/usernotifystdout_t.cpp index f81ffb5..29b6846 100644 --- a/src/twtest/usernotifystdout_t.cpp +++ b/src/twtest/usernotifystdout_t.cpp @@ -41,4 +41,10 @@ void TestUserNotifyStdout() { cDebug d("TestUserNotifyStdout"); d.TraceError("Implement this!\n"); + skip("TestUserNotifyStdout unimplemented"); +} + +void RegisterSuite_UserNotifyStdout() +{ + RegisterTest("UserNotifyStdout", "Basic", TestUserNotifyStdout); } diff --git a/src/twtest/wchar16_t.cpp b/src/twtest/wchar16_t.cpp index 83ad7b7..2d3a3c8 100644 --- a/src/twtest/wchar16_t.cpp +++ b/src/twtest/wchar16_t.cpp @@ -124,3 +124,8 @@ void TestWchar16() db.TraceAlways("Done...\n"); } + +void RegisterSuite_Wchar16() +{ + RegisterTest("Wchar16", "Basic", TestWchar16); +} From e453a81c879021cffed6f431eadac6e8f8d304d9 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Mon, 4 Sep 2017 01:35:27 -0700 Subject: [PATCH 24/29] Tweak unit tests that didn't invoke TEST() at all; add operator== to cFCOSpecAttr & cFSPropDisplayer for the sake of unit testing. --- src/twtest/configfile_t.cpp | 149 +++++++++++++++++------------- src/twtest/fcospecattr_t.cpp | 2 + src/twtest/fsdatasourceiter_t.cpp | 18 +++- src/twtest/fspropdisplayer_t.cpp | 16 ++-- src/twtest/platform_t.cpp | 8 +- src/twtest/policyparser_t.cpp | 1 + src/twtest/resources_t.cpp | 14 ++- src/twtest/serializer_t.cpp | 3 + src/twtest/stringutil_t.h | 2 + src/twtest/tchar_t.cpp | 17 ++-- src/twtest/test.cpp | 6 +- src/twtest/test.h | 1 + 12 files changed, 141 insertions(+), 96 deletions(-) diff --git a/src/twtest/configfile_t.cpp b/src/twtest/configfile_t.cpp index d62b03e..a2b032f 100644 --- a/src/twtest/configfile_t.cpp +++ b/src/twtest/configfile_t.cpp @@ -47,83 +47,101 @@ using namespace std; +static void assertParse(const std::string& configLineIn, bool expectValid) +{ + static const std::string sMandatory = \ + "\nPOLFILE=foo" \ + "\nDBFILE=foo" \ + "\nREPORTFILE=foo" \ + "\nSITEKEYFILE=foo" \ + "\nLOCALKEYFILE=foo"; + + bool threw = false; + cConfigFile cfg; + + std::string configLine = configLineIn + sMandatory; + + try + { + cfg.ReadString( configLine ); + } + catch( eConfigFileMissReqKey& e) + { + TCERR << "Got a missing key exception, which should not happen" << std::endl; + TEST(false); + } + catch( eConfigFile& e ) + { + e.SetFatality(false); + cTWUtil::PrintErrorMsg( e ); + + threw = true; + } + +#ifdef _DEBUG + TCERR << "LINE [" << configLineIn << "]" << std::endl << "Expected = " << expectValid << std::endl << "Threw = " << threw << std::endl; +#endif + + TEST(expectValid != threw); +} + + void TestConfigFile(void) { - TSTRING asConfigFileText[] = - { - _T("BRIAN=foo"), // 0 fine - _T("BRIAN=foo\nBILL=bar"), // 1 fine - _T("BRIAN=foo\r\nBILL=bar"), // 2 fine - _T("BRIAN=foo\n\n\rBILL=bar\n"),// 3 fine - _T(" WS=foo \n\n\r BILL=bar\n"), // 4 fine - _T(" WS = foo \n\n\r BILL = bar \n"), // 5 fine - _T("FOO=foo\nBAR=$(FOO)"), // 6 fine - _T("FOO=foo\nBAR=$(FO)"), // 7 undefined var - _T("FOO=foo\nBAR=$(FOO"), // 8 no r paren - _T("FOO=foo\nBAR=$(FOO "), // 9 no r paren - _T("BAR=$(FOO\n"), // 10 no r paren - _T(" VAR =foo \nWS = $(VAR)\n"), // 11 fine - _T(""), // 12 fine - _T("\n"), // 13 fine - _T("\r"), // 14 fine - _T("\r\n"), // 15 fine - _T("B=POO\nA"), // 16 no equals - _T(" B=POO \n A \r"), // 17 no equals - _T("B=POO\nB=CRAP"), // 18 redefined var - _T("DATE=CRAP"), // 19 redefine predefine var - _T("B=POO\nDATE=CRAP"), // 20 redefine predefine var - _T("A=1\nB=$(A)\nC=$(B)"), // 21 fine -- checking var sub - _T("A=$(DATE)"), // 22 fine -- checking predef var sub - _T("A=1\nB=$(A)\nC=$(DATE)"), // 23 fine -- checking predef var sub - _T("A=1\n=$(A)\nC=$(DATE)"), // 24 no key - _T("A=$(DATE)-B"), // 25 fine -- check that the '-' shows up - _T("A=$(DATE)-$(DATE)"), // 26 fine -- check that the '-' shows up - }; + // should succeed + assertParse( _T("BRIAN=foo"), true ); // 0 fine + assertParse( _T("BRIAN=foo\nBILL=bar"), true ); // 1 fine + assertParse( _T("BRIAN=foo\r\nBILL=bar"), true ); // 2 fine + assertParse( _T("BRIAN=foo\n\n\rBILL=bar\n"), true ); // 3 fine + assertParse( _T(" WS=foo \n\n\r BILL=bar\n"), true ); // 4 fine + assertParse( _T(" WS = foo \n\n\r BILL = bar \n"), true ); // 5 fine + assertParse( _T("FOO=foo\nBAR=$(FOO)"), true ); // 6 fine - /* - TSTRING sMandatory = \ - _T("\nPOLFILE=foo") \ - _T("\nDBFILE=foo") \ - _T("\nREPORTFILE=foo") \ - _T("\nSITEKEYFILE=foo") \ - _T("\nLOCALKEYFILE=foo"); - */ + // should fail + assertParse( _T("FOO=foo\nBAR=$(FO)"), false ); // 7 undefined var + assertParse( _T("FOO=foo\nBAR=$(FOO"), false ); // 8 no r paren + assertParse( _T("FOO=foo\nBAR=$(FOO "), false ); // 9 no r paren + assertParse( _T("BAR=$(FOO\n"), false ); // 10 no r paren + // should succeed + assertParse( _T(" VAR =foo \nWS = $(VAR)\n"), true ); // 11 fine + assertParse( _T(""), true ); // 12 fine + assertParse( _T("\n"), true ); // 13 fine + assertParse( _T("\r"), true ); // 14 fine + assertParse( _T("\r\n"), true ); // 15 fine - for( TSTRING* at = &asConfigFileText[0]; - at != &asConfigFileText[countof(asConfigFileText)]; - at++ ) - { - cConfigFile cfg; - //*at += sMandatory; + // should fail + assertParse( _T("B=POO\nA"), false ); // 16 no equals + assertParse( _T(" B=POO \n A \r"), false ); // 17 no equals + +/* This next test asserts that you can't change a variable once you've defined it. + However there's no actual code in cConfigFile to check for this, and + OST appears to work fine if you redefine a config variable, so I'm not going + to change the current behavior. Leaving this test in w/ a note for reference. + + assertParse( _T("B=POO\nB=CRAP"), false ); // 18 redefined var +*/ + assertParse( _T("DATE=CRAP"), false ); // 19 redefine predefine var + assertParse( _T("B=POO\nDATE=CRAP"), false ); // 20 redefine predefine var + // should succeed + assertParse( _T("A=1\nB=$(A)\nC=$(B)"), true ); // 21 fine -- checking var sub + assertParse( _T("A=$(DATE)"), true ); // 22 fine -- checking predef var sub + assertParse( _T("A=1\nB=$(A)\nC=$(DATE)"), true ); // 23 fine -- checking predef var sub + + // should fail + assertParse( _T("A=1\n=$(A)\nC=$(DATE)"), false ); // 24 no key + + // should succeed + assertParse( _T("A=$(DATE)-B"), true ); // 25 fine -- check that the '-' shows up + assertParse( _T("A=$(DATE)-$(DATE)"), true ); // 26 fine -- check that the '-' shows up - TCERR << _T("*** line:") << std::endl; - TCERR << *at << std::endl; - TCERR << _T("*** eol:") << std::endl; - try - { - cfg.ReadString( *at ); - } - catch( eConfigFileMissReqKey& ) - { - // ignore.... - } - catch( eConfigFile& e ) - { - int offset = ( at - asConfigFileText ); - int itemSize = sizeof( asConfigFileText[0] ); - int num = offset / itemSize; - TCERR << num << std::endl; - cTWUtil::PrintErrorMsg( e ); - } - } } void TestConfigFile2(void) { cDebug d("Testconfigfile"); d.TraceDetail("Entering...\n"); - iFSServices* pFSServices = iFSServices::GetInstance(); + //iFSServices* pFSServices = iFSServices::GetInstance(); //Define some test values for pairs to be //stored in a test config. module. I'm going to use the @@ -175,7 +193,6 @@ void TestConfigFile2(void) TEST( lookup2 == "test.twd" ); d.TraceDetail("Tests Passed!\n"); -//#endif // NOT_BRIANS_TEST } void RegisterSuite_ConfigFile() diff --git a/src/twtest/fcospecattr_t.cpp b/src/twtest/fcospecattr_t.cpp index 6ffc8fe..d483fe8 100644 --- a/src/twtest/fcospecattr_t.cpp +++ b/src/twtest/fcospecattr_t.cpp @@ -85,6 +85,8 @@ void TestFCOSpecAttr() // trace contents... TraceSpecAttr(pNew, d); + TEST( *pAttr == *pNew ); + pNew->Release(); pAttr->Release(); } diff --git a/src/twtest/fsdatasourceiter_t.cpp b/src/twtest/fsdatasourceiter_t.cpp index 1917128..21608a3 100644 --- a/src/twtest/fsdatasourceiter_t.cpp +++ b/src/twtest/fsdatasourceiter_t.cpp @@ -62,13 +62,12 @@ static void PrintDb( cHierDatabase::iterator iter, cDebug d, bool bFirst = true static void PrintIter( cFSDataSourceIter iter, cDebug& d ) { - // - //debug stuff - // - + int count = 0; + if( ! iter.CanDescend() ) { d.TraceError( "Iterator cannot descend; returning!\n"); + TEST(!"Unexpected !CanDescend at beginning of test"); return; } iter.Descend(); @@ -76,6 +75,7 @@ static void PrintIter( cFSDataSourceIter iter, cDebug& d ) for( iter.SeekBegin(); ! iter.Done(); iter.Next() ) { + count++; iFCO* pFCO = iter.CreateFCO(); if( pFCO ) { @@ -85,6 +85,7 @@ static void PrintIter( cFSDataSourceIter iter, cDebug& d ) else { d.TraceError( "*** Create of FCO failed!\n"); + fail("CreateFCO() failure"); } if( iter.CanDescend() ) { @@ -92,16 +93,23 @@ static void PrintIter( cFSDataSourceIter iter, cDebug& d ) PrintIter(iter, d); } } + + TEST(count > 0); } void TestFSDataSourceIter() { + skip("Fix this test"); + cFSDataSourceIter iter; cDebug d("TestFSDataSourceIter"); + cFCOName base(TwTestDir()); + // go to my temp directory and iterate over everything! - iter.SeekToFCO( cFCOName(_T("/tmp")) ); + iter.SeekToFCO( cFCOName(TwTestDir()) ); + // // print out everything below the iterator // diff --git a/src/twtest/fspropdisplayer_t.cpp b/src/twtest/fspropdisplayer_t.cpp index d1fdf82..e2b5c3d 100644 --- a/src/twtest/fspropdisplayer_t.cpp +++ b/src/twtest/fspropdisplayer_t.cpp @@ -83,11 +83,11 @@ void cTestFSPropDisplayer::Test() pPDNew->Merge( pPD ); - /* + //////////////////////// // write pd cFileArchive outFile; - outFile.OpenReadWrite(_T("c:\\tmp\\tmp.pd")); + outFile.OpenReadWrite( TwTestPath("tmp.pd").c_str() ); cSerializerImpl outSer(outFile, cSerializerImpl::S_WRITE); outSer.Init(); @@ -101,16 +101,17 @@ void cTestFSPropDisplayer::Test() //////////////////////// // read pd cFileArchive inFile; - inFile.OpenRead(_T("c:\\tmp\\tmp.pd")); + inFile.OpenRead( TwTestPath("tmp.pd").c_str() ); cSerializerImpl inSer(inFile, cSerializerImpl::S_READ); - cFSPropDisplayer* pPDNew = new cFSPropDisplayer(); + cFSPropDisplayer* pPDRead = new cFSPropDisplayer(); inSer.Init(); - pPDNew->Read( &inSer ); + pPDRead->Read( &inSer ); inSer.Finit(); - */ - + + TEST( *pPD == *pPDRead ); + TSTRING strRet; for( i = 0; i < 26; i++ ) { @@ -129,6 +130,7 @@ void cTestFSPropDisplayer::Test() delete pPD; delete pPDNew; + delete pPDRead; return; } diff --git a/src/twtest/platform_t.cpp b/src/twtest/platform_t.cpp index b4ed007..bf63b62 100644 --- a/src/twtest/platform_t.cpp +++ b/src/twtest/platform_t.cpp @@ -119,10 +119,14 @@ AlignMe::AlignMe() TCOUT << _T("Writing...") << std::endl; *pb = I; // access memory for write TCOUT << _T("Write succeeded.") << std::endl; -#endif + TCOUT << _T("Alignment of ") << ALIGN_SIZE << _T(" ") << ( ALIGN_SIZE == 1 ? _T("byte") : _T("bytes") ) << _T(" is OK") << std::endl << _T("=========================================\n"); + + TEST("Aligned"); // The actual test is not bus erroring up above; this just tells the framework we tested something. + +#endif } @@ -173,6 +177,7 @@ void TestAlignment() *pi = *pi; // misaligned access (read and write) TCOUT << _T("Misaligned access OK.") << std::endl; + TEST("Misaligned ok"); //again, the test is not exploding up above // - - - - - - - - - - - - - - - - - - - - - - // make sure our BYTE_ALIGN value is correct -- @@ -198,6 +203,7 @@ void TestAlignment() TCOUT << _T("Aligned access OK. BYTE_ALIGN value of ") << BYTE_ALIGN << _T(" is good.") << std::endl; TCOUT << _T("=========================================\n"); + TEST("BYTE_ALIGN ok"); // yet again, the test is not falling over a couple of lines up. } void TestSizes() diff --git a/src/twtest/policyparser_t.cpp b/src/twtest/policyparser_t.cpp index 6070e2d..828080b 100644 --- a/src/twtest/policyparser_t.cpp +++ b/src/twtest/policyparser_t.cpp @@ -89,6 +89,7 @@ void test_policy_file(const std::string& polfile) errorQ.SetChild( &errorT ); parser.Execute( policy, &errorQ ); + TEST("No exceptions thrown in cPolicyParser::Execute"); TCERR << "Parsed policy test file " << polfile << std::endl; return; diff --git a/src/twtest/resources_t.cpp b/src/twtest/resources_t.cpp index b2533e3..9a35abb 100644 --- a/src/twtest/resources_t.cpp +++ b/src/twtest/resources_t.cpp @@ -84,15 +84,13 @@ TSS_ImplementPackage( cTestResources ) void TestResources() { TSS_Package( cTestResources ).Count( 20 ); - - TCOUT << _T("Package::Count(") << TSS_Package( cTestResources ).Count() << _T(")\n" ) << std::endl; - TCOUT << TSS_GetString( cTestResources, test::IDS_TEST1 ) << std::endl; - TCOUT << TSS_GetString( cTestResources, test::IDS_TEST2 ) << std::endl; - TCOUT << TSS_GetString( cTestResources, test::IDS_TEST3 ) << std::endl; - TCOUT << TSS_GetString( cTestResources, test::IDS_INVALID ) << std::endl; - - + TEST( TSS_Package( cTestResources ).Count() == 20) ; + TEST( TSS_GetString( cTestResources, test::IDS_TEST1 ) == _T("Test String 1") ); + TEST( TSS_GetString( cTestResources, test::IDS_TEST2 ) == _T("Test String 2") ); + TEST( TSS_GetString( cTestResources, test::IDS_TEST3 ) == _T("Test String 3") ); + TEST( TSS_GetString( cTestResources, test::IDS_INVALID ) == _T("") ); + TEST( TSS_GetString( cTestResources, 42 ) == _T("") ); } void RegisterSuite_Resources() diff --git a/src/twtest/serializer_t.cpp b/src/twtest/serializer_t.cpp index 2244f05..498a2c9 100644 --- a/src/twtest/serializer_t.cpp +++ b/src/twtest/serializer_t.cpp @@ -71,6 +71,9 @@ cSerTestObject::cSerTestObject() void TestSerializer() { cSerTestObject test_obj; + + TEST( std::string(test_obj.GetType().AsString()) == std::string("cSerTestObject") ); + TEST( test_obj.Version() == 1); } void RegisterSuite_Serializer() diff --git a/src/twtest/stringutil_t.h b/src/twtest/stringutil_t.h index 70117f0..1d8494d 100644 --- a/src/twtest/stringutil_t.h +++ b/src/twtest/stringutil_t.h @@ -167,6 +167,8 @@ void TestStringUtil() TEST(tStr.length() == 9); db.TraceAlways("Done...\n"); +#else + skip("Implement this for non-DBS, i.e. most everywhere."); #endif // USING_NTDBS_STUFF } diff --git a/src/twtest/tchar_t.cpp b/src/twtest/tchar_t.cpp index 702bd79..fa48662 100644 --- a/src/twtest/tchar_t.cpp +++ b/src/twtest/tchar_t.cpp @@ -46,13 +46,15 @@ void test_wist(const TSTRING&, cDebug& d); void TestTCHAR() { + TCERR << "TODO: Right now this test mostly verifies that STL string & file classes work, which is not overly useful." << std::endl; + cDebug d("TestTCHAR()"); d.TraceDetail("Entering...\n"); //Testing TCOUT: TCOUT<< _T("Simple test of TSTRING (and TCOUT) :\n\n"); - TCERR<< _T("This should show up on cerr"); + TCERR<< _T("This should show up on cerr") << std::endl; TSTRING pString; pString = _T("Hi Mom!"); @@ -82,7 +84,7 @@ void TestTCHAR() //A true statement! d.TraceDetail("Testing TISTRINGSTREAM with TSTRING:\n"); - TSTRING send = _T("These should appear on seperate lines"); + TSTRING send = _T("These should appear on separate lines"); test_wist(send, d); //Did they? @@ -100,19 +102,18 @@ void TestTCHAR() TIFSTREAM from; from.open(inputfile.c_str(), std::ios_base::in); - if(!from) - d.TraceDetail("error opening input file\n"); + TEST(from); + TOFSTREAM to(outputfile.c_str(), std::ios_base::trunc); - if(!to) - d.TraceDetail("error opening output file\n"); + TEST(to); //Copy contents of input file to output file. TCHAR ch; while(from.get(ch)) to.put(ch); - if(!from.eof() || !to) - d.TraceDetail("something has gone terribly wrong...\n"); + + TEST(from.eof() && to); return; } diff --git a/src/twtest/test.cpp b/src/twtest/test.cpp index 69cca93..ff84c76 100644 --- a/src/twtest/test.cpp +++ b/src/twtest/test.cpp @@ -159,10 +159,14 @@ void skip(const std::string& reason) throw skip_exception(reason); } +void fail(const std::string& reason) +{ + throw std::runtime_error(reason); +} + void CountMacro() { macro_count++; - TCERR << "*** Incrementing macro count, value is now" << macro_count << std::endl;; } ///////////////////////// diff --git a/src/twtest/test.h b/src/twtest/test.h index 90351bb..db1d32d 100644 --- a/src/twtest/test.h +++ b/src/twtest/test.h @@ -90,6 +90,7 @@ typedef std::map< std::string, SuiteMap > TestMap; void RegisterTest(const std::string& suite, const std::string testName, TestPtr testPtr ); void skip(const std::string& reason); +void fail(const std::string& reason); #endif // __TEST_H From 25ddcc0ca61d8d75d6719e00aafead105af8cc3f Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Mon, 4 Sep 2017 11:47:35 -0700 Subject: [PATCH 25/29] Break some big unit tests into smaller ones --- src/fco/fcospecattr.cpp | 6 ++ src/fco/fcospecattr.h | 2 + src/fs/fspropdisplayer.cpp | 7 +- src/fs/fspropdisplayer.h | 3 + src/twtest/archive_t.cpp | 78 ++++++++++++------ src/twtest/fcopropimpl_t.cpp | 17 ++-- src/twtest/signature_t.cpp | 127 ++++++++++++++++++++++------- src/twtest/unixfsservices_t.cpp | 138 +++++++++++++++++++++----------- 8 files changed, 269 insertions(+), 109 deletions(-) diff --git a/src/fco/fcospecattr.cpp b/src/fco/fcospecattr.cpp index 8f7cbd9..9394c80 100644 --- a/src/fco/fcospecattr.cpp +++ b/src/fco/fcospecattr.cpp @@ -92,4 +92,10 @@ void cFCOSpecAttr::TraceContents(int dl) const } } +bool cFCOSpecAttr::operator==(const cFCOSpecAttr& rhs) const +{ + return ( (mEmailAddrs == rhs.mEmailAddrs) + && (mName == rhs.mName) + && (mSeverity == rhs.mSeverity)); +} diff --git a/src/fco/fcospecattr.h b/src/fco/fcospecattr.h index 1924bf8..746e9dc 100644 --- a/src/fco/fcospecattr.h +++ b/src/fco/fcospecattr.h @@ -76,6 +76,8 @@ public: void TraceContents(int dl = -1) const; + bool operator==(const cFCOSpecAttr& rhs) const; + DECLARE_SERREFCOUNT() private: cFCOSpecAttr (const cFCOSpecAttr& rhs); // not impl diff --git a/src/fs/fspropdisplayer.cpp b/src/fs/fspropdisplayer.cpp index 375cf67..28e733f 100644 --- a/src/fs/fspropdisplayer.cpp +++ b/src/fs/fspropdisplayer.cpp @@ -509,4 +509,9 @@ bool cFSPropDisplayer::AddGroupnameMapping( const int64& i64gid, const TSTRING& return( ret.second = false ); // returns true if key didn't exist before } - +bool cFSPropDisplayer::operator==(const cFSPropDisplayer& rhs) const +{ + return (mpvPropsWeDisplay == rhs.mpvPropsWeDisplay + && uidToUsername == rhs.uidToUsername + && gidToGroupname == rhs.gidToGroupname); +} diff --git a/src/fs/fspropdisplayer.h b/src/fs/fspropdisplayer.h index 91164b6..780bfe4 100644 --- a/src/fs/fspropdisplayer.h +++ b/src/fs/fspropdisplayer.h @@ -114,6 +114,9 @@ public: virtual bool GetLazy() const; virtual void Read (iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive) virtual void Write(iSerializer* pSerializer) const; // throw (eSerializer, eArchive) + + bool operator==(const cFSPropDisplayer& rhs) const; // for testing + private: void AddMapping( const iFCOProp* const pProp, const TSTRING& tstrValue, const int propTypeEnum ); // pass in a property value and its string representation. for instance: ( FS::PROP_UID --> username ) diff --git a/src/twtest/archive_t.cpp b/src/twtest/archive_t.cpp index 3db5e8a..cf6410f 100644 --- a/src/twtest/archive_t.cpp +++ b/src/twtest/archive_t.cpp @@ -42,7 +42,7 @@ TSS_EXCEPTION(eTestArchiveError, eError); -void TestArchive() +void TestMemoryArchive() { // cMemoryArchive cMemoryArchive memarch; @@ -52,7 +52,7 @@ void TestArchive() memarch.WriteInt32(3); memarch.WriteInt32(4); - TSTRING s = _T("Weenus"); + TSTRING s = _T("Iridogorgia"); memarch.WriteString(s); memarch.WriteInt64(1234567L); @@ -74,7 +74,7 @@ void TestArchive() TSTRING s2; memarch.ReadString(s2); - TEST(s2.compare(_T("Weenus")) == 0); + TEST(s2.compare(_T("Iridogorgia")) == 0); memarch.ReadInt64(l); TEST(l == 1234567L); @@ -101,37 +101,61 @@ void TestArchive() TEST(memarch.GetMappedOffset() == 4 * sizeof(int32) + sizeof(int32) + 6); TEST(memarch.GetMappedLength() == sizeof(int64)); // TEST(tw_ntohll(*(int64*)memarch.GetMap()) == 1234567L); +} +void TestLockedTemporaryArchive() +{ + TSTRING s = _T("Metallogorgia"); + bool threw = false; // cLockedTemporaryFileArchive TSTRING lockedFileName = TwTestPath("inaccessable_file.bin"); -// lockedFileName += _T("/inaccessable_file.bin"); cLockedTemporaryFileArchive lockedArch; - // try to create an archive using a temp file - lockedArch.OpenReadWrite(); - lockedArch.Close(); + try + { + // try to create an archive using a temp file + lockedArch.OpenReadWrite(); + lockedArch.Close(); + } + catch (...) + { + threw = true; + } - // this should open and lock the file -- shouldn't be able to access it - lockedArch.OpenReadWrite(lockedFileName.c_str()); - lockedArch.Seek(0, cBidirArchive::BEGINNING); + try + { + // this should open and lock the file -- shouldn't be able to access it + lockedArch.OpenReadWrite(lockedFileName.c_str()); + lockedArch.Seek(0, cBidirArchive::BEGINNING); - // shouldn't be able to see these changes - lockedArch.WriteInt32(1); - lockedArch.WriteInt32(2); - lockedArch.WriteInt32(3); - lockedArch.WriteInt32(4); - lockedArch.WriteString(s); - lockedArch.WriteInt64(1234567L); - lockedArch.WriteInt16(42); + // shouldn't be able to see these changes + lockedArch.WriteInt32(1); + lockedArch.WriteInt32(2); + lockedArch.WriteInt32(3); + lockedArch.WriteInt32(4); + lockedArch.WriteString(s); + lockedArch.WriteInt64(1234567L); + lockedArch.WriteInt16(42); - // this should delete the file - lockedArch.Close(); + // this should delete the file + lockedArch.Close(); + } + catch (...) + { + threw = true; + } - // cFileArchive + TEST(!threw); +} + +void TestFileArchive() +{ + bool threw = false; + TSTRING s = _T("Acanthogorgia"); + // cFileArchive TSTRING fileName = TwTestPath("archive_test.bin"); - //fileName += _T("/archive_test.bin"); cFileArchive filearch; filearch.OpenReadWrite(fileName.c_str()); @@ -163,7 +187,7 @@ void TestArchive() TSTRING s3; filearch.ReadString(s3); - TEST(s3.compare(_T("Weenus")) == 0); + TEST(s3.compare(_T("Acanthogorgia")) == 0); filearch.ReadInt64(k); TEST(k == 1234567L); @@ -181,12 +205,16 @@ void TestArchive() } catch (eError& e) { - TEST(false); + threw=true; (void)e; } + + TEST(!threw); } void RegisterSuite_Archive() { - RegisterTest("Archive", "Basic", TestArchive); + RegisterTest("Archive", "MemoryArchive", TestMemoryArchive); + RegisterTest("Archive", "LockedTemporaryArchive)", TestLockedTemporaryArchive); + RegisterTest("Archive", "FileArchive", TestFileArchive); } diff --git a/src/twtest/fcopropimpl_t.cpp b/src/twtest/fcopropimpl_t.cpp index 492a36f..18b472d 100644 --- a/src/twtest/fcopropimpl_t.cpp +++ b/src/twtest/fcopropimpl_t.cpp @@ -35,9 +35,9 @@ #include "core/debug.h" #include "twtest/test.h" -void TestFCOPropImpl() +void TestNumeric() { - cDebug d("TestFCOPropImpl"); + cDebug d("TestNumeric"); d.TraceDebug("Entering...\n"); // print the enum key: @@ -69,12 +69,18 @@ void TestFCOPropImpl() d.TraceDebug("333ui64 == 456ui64 = %d\n", pui64.Compare(&pui64b, iFCOProp::OP_EQ)); TEST( iFCOProp::CMP_FALSE == p2i64.Compare(&pi64, iFCOProp::OP_EQ)); - +} + +void TestStrings() +{ + cDebug d("TestStrings"); cFCOPropTSTRING pt1; cFCOPropTSTRING pt2; pt1.SetValue(TSTRING(_T("bar"))); pt2.SetValue(TSTRING(_T("foo"))); - + cFCOPropInt64 pi64; + pi64.SetValue(8675309); + d.TraceDebug(_T("property TSTRING = (should be \"bar\") %s\n"), pt1.AsString().c_str()); TEST(pt1.AsString() == "bar"); @@ -96,5 +102,6 @@ void TestFCOPropImpl() void RegisterSuite_FCOPropImpl() { - RegisterTest("FCOPropImpl", "Basic", TestFCOPropImpl); + RegisterTest("FCOPropImpl", "Numeric", TestNumeric); + RegisterTest("FCOPropImpl", "Strings", TestStrings); } diff --git a/src/twtest/signature_t.cpp b/src/twtest/signature_t.cpp index 82b4b7d..30e54f6 100644 --- a/src/twtest/signature_t.cpp +++ b/src/twtest/signature_t.cpp @@ -43,11 +43,38 @@ using namespace std; -void TestSignature() +std::string getTestFile() +{ + // Create a file for which we know the signatures + // + //% siggen ~/signature_test.bin + //crc : AAAAAAAAAAy + //md5 : B/Y8ttBnlyw/NPCUu353ao + //crc32 : B1kP9v + //sha : Oia1aljHD793tfj7M55tND+3OG/ + //haval : BL6bFSo0EP5zf8lGSueeed + + static TSTRING sigFileName; + + if (sigFileName.empty()) + { + sigFileName = TwTestPath("signature_test.bin"); + + cFileArchive fileArc; + fileArc.OpenReadWrite(sigFileName.c_str()); + fileArc.WriteBlob("\x1\x2\x3\x4\x5\x6\x7\x8\x9\x0", 10); + fileArc.Close(); + } + + return sigFileName; +} + + +void TestSignatureBasic() { // Signature usage example (?) cCRC32Signature crcSig; - cDebug d("TestSignature"); + cDebug d("TestSignature1"); byte abData[ 64 ]; int i; @@ -58,7 +85,6 @@ void TestSignature() crcSig.Update( &abData[0], 32 ); crcSig.Update( &abData[32], 32 ); crcSig.Finit(); - TCOUT << _T("new way: ") << crcSig.AsString() << endl; cMemoryArchive arch; arch.WriteBlob( &abData[0], 32 ); @@ -69,32 +95,19 @@ void TestSignature() asg.AddSig( &crc ); asg.CalculateSignatures( arch ); - TCOUT << _T("old way: ") << crc.AsString() << endl; - + TEST( crc.AsStringHex() == crcSig.AsStringHex()); +} // Note: The following causes an ASSERT() in iSignature::Compare(), as it should, but // we don't want asserts to occur in a working test suite! // TEST(nullSig.Compare(&checksumSig, iFCOProp::OP_EQ) == iFCOProp::CMP_WRONG_PROP_TYPE); - - // Create a file for which we know the signatures - // - //% siggen ~/signature_test.bin - //crc : AAAAAAAAAAy - //md5 : B/Y8ttBnlyw/NPCUu353ao - //crc32 : B1kP9v - //sha : Oia1aljHD793tfj7M55tND+3OG/ - //haval : BL6bFSo0EP5zf8lGSueeed - - TSTRING sigFileName = TwTestPath("signature_test.bin"); - +void TestChecksum() +{ + TSTRING sigFileName = getTestFile(); cFileArchive fileArc; - fileArc.OpenReadWrite(sigFileName.c_str()); - fileArc.WriteBlob("\x1\x2\x3\x4\x5\x6\x7\x8\x9\x0", 10); - fileArc.Close(); - - + cDebug d("TestChecksum"); // test begins here // general signature & archive variables @@ -145,8 +158,19 @@ void TestSignature() check2.Read(&readSer); TEST(check1.Compare(&check2, iFCOProp::OP_EQ) == iFCOProp::CMP_TRUE); } +} + +void TestCRC32() +{ + TSTRING sigFileName = getTestFile(); + cFileArchive fileArc; + cDebug d("TestCRC32"); + + // general signature & archive variables + byte abBuf[iSignature::SUGGESTED_BLOCK_SIZE]; + const int cbToRead = iSignature::SUGGESTED_BLOCK_SIZE; + int cbRead; - // test CRC32 cCRC32Signature crc1, crc2; d.TraceDetail("Testing CRC32.\n"); @@ -190,7 +214,18 @@ void TestSignature() crc2.Read(&readSer); TEST(crc1.Compare(&crc2, iFCOProp::OP_EQ) == iFCOProp::CMP_TRUE); } +} +void TestMD5() +{ + TSTRING sigFileName = getTestFile(); + cFileArchive fileArc; + cDebug d("TestMD5"); + + // general signature & archive variables + byte abBuf[iSignature::SUGGESTED_BLOCK_SIZE]; + const int cbToRead = iSignature::SUGGESTED_BLOCK_SIZE; + int cbRead; // test MD5 cMD5Signature md51, md52; @@ -235,7 +270,18 @@ void TestSignature() md52.Read(&readSer); TEST(md51.Compare(&md52, iFCOProp::OP_EQ) == iFCOProp::CMP_TRUE); } +} +void TestSHA1() +{ + TSTRING sigFileName = getTestFile(); + cFileArchive fileArc; + cDebug d("TestSHA1"); + + // general signature & archive variables + byte abBuf[iSignature::SUGGESTED_BLOCK_SIZE]; + const int cbToRead = iSignature::SUGGESTED_BLOCK_SIZE; + int cbRead; // test SHA cSHASignature sha1, sha2; @@ -280,8 +326,19 @@ void TestSignature() sha2.Read(&readSer); TEST(sha1.Compare(&sha2, iFCOProp::OP_EQ) == iFCOProp::CMP_TRUE); } +} + +void TestHAVAL() +{ + TSTRING sigFileName = getTestFile(); + cFileArchive fileArc; + cDebug d("TestHAVAL"); + + // general signature & archive variables + byte abBuf[iSignature::SUGGESTED_BLOCK_SIZE]; + const int cbToRead = iSignature::SUGGESTED_BLOCK_SIZE; + int cbRead; - // test HAVAL cHAVALSignature haval1, haval2; d.TraceDetail("Testing HAVAL.\n"); @@ -322,10 +379,16 @@ void TestSignature() haval1.Write(&writeSer); sigArchive.Seek(0, cBidirArchive::BEGINNING); cSerializerImpl readSer(sigArchive, cSerializerImpl::S_READ); - md52.Read(&readSer); + haval2.Read(&readSer); TEST(haval1.Compare(&haval2, iFCOProp::OP_EQ) == iFCOProp::CMP_TRUE); } - +} + +void TestArchiveSigGen() +{ + TSTRING sigFileName = getTestFile(); + cFileArchive fileArc; + cDebug d("TestArchiveSigGen"); // test cArchiveSigGen cArchiveSigGen asgtest; @@ -356,12 +419,16 @@ void TestSignature() TEST(haval3.AsString().compare(_T("BL6bFSo0EP5zf8lGSueeed")) == 0); TEST(haval3.AsStringHex().compare(_T("4be9b152a3410fe737fc9464ae79e79d")) == 0); - fileArc.Close(); - - return; + fileArc.Close(); } void RegisterSuite_Signature() { - RegisterTest("Signature", "Basic", TestSignature); + RegisterTest("Signature", "Basic", TestSignatureBasic); + RegisterTest("Signature", "Checksum", TestChecksum); + RegisterTest("Signature", "CRC32", TestCRC32); + RegisterTest("Signature", "MD5", TestMD5); + RegisterTest("Signature", "SHA1", TestSHA1); + RegisterTest("Signature", "HAVAL", TestHAVAL); + RegisterTest("Signature", "ArchiveSigGen", TestArchiveSigGen); } diff --git a/src/twtest/unixfsservices_t.cpp b/src/twtest/unixfsservices_t.cpp index 45acdbb..70865fe 100644 --- a/src/twtest/unixfsservices_t.cpp +++ b/src/twtest/unixfsservices_t.cpp @@ -44,12 +44,24 @@ using namespace std; -//Tests the functions that are currently implemented in win32fsservices. -void TestUnixFSServices() -{ - cDebug d("TestUnixFSServices"); - // d.RemoveOutTarget(cDebug::OUT_STDOUT); +std::string makeTestFile(const std::string &filename) +{ + TSTRING testfile = TwTestPath(filename); + cFileArchive filearch; + filearch.OpenReadWrite(testfile.c_str()); + filearch.Seek(0, cBidirArchive::BEGINNING); + filearch.WriteString(_T("This is a test")); + filearch.Close(); + + return testfile; +} + +//Tests the functions that are currently implemented in win32fsservices. +void TestReadDir() +{ + cDebug d("TestReadDir"); + // d.RemoveOutTarget(cDebug::OUT_STDOUT); iFSServices* pFSServices = iFSServices::GetInstance(); @@ -75,20 +87,20 @@ void TestUnixFSServices() TEST(n == v.size()); } +} +void TestStat() +{ //Test the Stat method cFSStatArgs stat; - //TO DO: use archive to create this file - TSTRING testfile = TwTestPath("tmp.tmp"); - cFileArchive filearch; - filearch.OpenReadWrite(testfile.c_str()); - filearch.Seek(0, cBidirArchive::BEGINNING); - filearch.WriteString(_T("This is a test")); - filearch.Close(); + std::string testfile = makeTestFile("stat.tmp"); - pFSServices->Stat(testfile, stat); + iFSServices::GetInstance()->Stat(testfile, stat); + TEST("Stat() did not throw"); +/* + cDebug d("TestStat"); //print out the information returned by Stat d.TraceDetail("Information returned by Stat: \n"); d.TraceDetail("Group ID : %-5d \n", stat.gid); @@ -102,65 +114,95 @@ void TestUnixFSServices() d.TraceDetail("Major/minor dev if special: %d \n", stat.rdev); d.TraceDetail("File size: %d \n", stat.size); d.TraceDetail("User ID: %d \n", stat.uid); +*/ +} - //Test GetCurrentDir: +void TestGetCurrentDir() +{ TSTRING currpath; - pFSServices->GetCurrentDir(currpath); - d.TraceDetail("GetCurrentDir returned %s\n", currpath.c_str()); + iFSServices::GetInstance()->GetCurrentDir(currpath); + + TEST("GetCurrentDir() did not throw"); + + //d.TraceDetail("GetCurrentDir returned %s\n", currpath.c_str()); //TEST(currpath == _T("~")); //they should both be ~!! +} - //Test MakeTempFilename +void TestMakeTempFilename() +{ TSTRING _template(_T("twtempXXXXXX")); - pFSServices->MakeTempFilename(_template); - d.TraceDetail("Testing MakeTempFilename: \n"); - d.TraceDetail("%s \n", _template.c_str() ); + iFSServices::GetInstance()->MakeTempFilename(_template); - // Test GetMachineName - d.TraceDetail("Testing GetMachineName:\n"); + TEST("MakeTempFilename() did not throw"); +} + +void TestGetMachineName() +{ TSTRING uname; - pFSServices->GetMachineName(uname); - d.TraceDetail("GetMachineName returned: %s\n", uname.c_str()); + iFSServices::GetInstance()->GetMachineName(uname); - // Test GetHostID - d.TraceDetail("Testing GetHostID:\n"); + TEST("GetMachineName() did not throw"); +} + +void TestGetHostID() +{ TSTRING hostid; - pFSServices->GetHostID(hostid); - d.TraceDetail("GetHostID returned: %s\n", hostid.c_str()); + iFSServices::GetInstance()->GetHostID(hostid); - // Test GetCurrentUserName - d.TraceDetail("Testing GetCurrentUserName:\n"); + TEST("GetHostID() did not throw:"); +} + +void TestGetCurrentUserName() +{ TSTRING username; - TEST( pFSServices->GetCurrentUserName(username) ); - d.TraceDetail("GetCurrentUserName returned: %s\n", username.c_str()); + TEST( iFSServices::GetInstance()->GetCurrentUserName(username) ); +} - // Test GetIPAddress - d.TraceDetail("Testing GetIPAddress:\n"); +void TestGetIPAddress() +{ uint32 ipaddr; - TEST( pFSServices->GetIPAddress( ipaddr ) ); - d.TraceDetail("GetIPAddress returned: %d\n", ipaddr); + TEST( iFSServices::GetInstance()->GetIPAddress( ipaddr ) ); +} - // test GetExecutableFilename - d.TraceDetail("Testing GetExecutableFilename: \n"); +void TestGetExecutableFilename() +{ TSTRING filename = _T("sh"); TSTRING fullpath = _T("/bin/"); - TEST(pFSServices->GetExecutableFilename(fullpath, filename)); + TEST( iFSServices::GetInstance()->GetExecutableFilename(fullpath, filename)); + filename = _T("/bin/sh"); - TEST(pFSServices->GetExecutableFilename(fullpath, filename)); + TEST( iFSServices::GetInstance()->GetExecutableFilename(fullpath, filename)); +} - // test Rename - d.TraceDetail("Testing Rename:\n"); - TSTRING newtestfile = TwTestPath("new.tmp"); - TEST( pFSServices->Rename( testfile, newtestfile ) ); +void TestRename() +{ + std::string testfile = makeTestFile("rename_from"); - // test FileDelete - d.TraceDetail("Testing FileDelete:\n"); - TEST( pFSServices->FileDelete( newtestfile ) ); + TSTRING newtestfile = TwTestPath("rename_to"); + TEST( iFSServices::GetInstance()->Rename( testfile, newtestfile ) ); +} + +void TestFileDelete() +{ + std::string to_rm = makeTestFile("to_rm"); + + TEST( iFSServices::GetInstance()->FileDelete( to_rm ) ); } void RegisterSuite_UnixFSServices() { - RegisterTest("UnixFSServices", "Basic", TestUnixFSServices); + RegisterTest("UnixFSServices", "ReadDir", TestReadDir); + RegisterTest("UnixFSServices", "Stat", TestStat); + RegisterTest("UnixFSServices", "GetCurrentDir", TestGetCurrentDir); + RegisterTest("UnixFSServices", "MakeTempFilename", TestMakeTempFilename); + RegisterTest("UnixFSServices", "GetMachineName", TestGetMachineName); + RegisterTest("UnixFSServices", "GetHostID", TestGetHostID); + RegisterTest("UnixFSServices", "GetCurrentUserName", TestGetCurrentUserName); + RegisterTest("UnixFSServices", "GetIPAddress", TestGetIPAddress); + RegisterTest("UnixFSServices", "GetExecutableFilename", TestGetExecutableFilename); + RegisterTest("UnixFSServices", "Rename", TestRename); + RegisterTest("UnixFSServices", "FileDelete", TestFileDelete); } From a47236408c4ef110ca5fb1acdca77af9982b6f60 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Mon, 4 Sep 2017 13:31:44 -0700 Subject: [PATCH 26/29] Add tests to check MD5 & SHA1 impls against RFC test cases --- src/twtest/signature_t.cpp | 84 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/src/twtest/signature_t.cpp b/src/twtest/signature_t.cpp index 30e54f6..13ad64d 100644 --- a/src/twtest/signature_t.cpp +++ b/src/twtest/signature_t.cpp @@ -422,6 +422,88 @@ void TestArchiveSigGen() fileArc.Close(); } +void assertMD5(const std::string& source, const std::string& expectedHex) +{ + // Signature usage example (?) + cMD5Signature md5Sig; + + md5Sig.Init(); + md5Sig.Update( (const byte*)source.c_str(), source.length() ); + md5Sig.Finit(); + + TEST( md5Sig.AsStringHex() == expectedHex); +} + +void assertSHA1(const std::string& source, const std::string& expectedHex) +{ + // Signature usage example (?) + cSHASignature shaSig; + + shaSig.Init(); + shaSig.Update( (const byte*)source.c_str(), source.length() ); + shaSig.Finit(); + + TCERR << "Source = [" << source << "]" << std::endl; + TCERR << "Expected = " << expectedHex << std::endl; + TCERR << "Observed = " << shaSig.AsStringHex() << std::endl; + + TEST( shaSig.AsStringHex() == expectedHex); +} + + +void TestRFC1321() +{ + // All MD5 test cases from RFC 1321, appendix A.5 + // https://www.ietf.org/rfc/rfc1321.txt + + assertMD5("", "d41d8cd98f00b204e9800998ecf8427e"); + assertMD5("a", "0cc175b9c0f1b6a831c399e269772661"); + assertMD5("abc", "900150983cd24fb0d6963f7d28e17f72"); + assertMD5("message digest", "f96b697d7cb7938d525a2f31aaf161d0"); + assertMD5("abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b"); + assertMD5( + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", + "d174ab98d277d9f5a5611c2c9f419d9f"); + assertMD5( + "12345678901234567890123456789012345678901234567890123456789012345678901234567890", + "57edf4a22be3c955ac49da2e2107b67a"); +} + +void TestRFC3174() +{ + // SHA1 test cases from RFC 3174, section 7.3 + // https://www.ietf.org/rfc/rfc3174.txt + // plus BSD libmd test cases + // https://opensource.apple.com/source/libmd/libmd-3/Makefile + // + // TODO: Compare against NIST test vectors for extra pedanticity + // http://csrc.nist.gov/groups/STM/cavp/secure-hashing.html + + assertSHA1("abc", "a9993e364706816aba3e25717850c26c9cd0d89d"); + assertSHA1( + "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + "84983e441c3bd26ebaae4aa1f95129e5e54670f1"); + + assertSHA1("a", "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8"); + assertSHA1( + "0123456701234567012345670123456701234567012345670123456701234567", + "e0c094e867ef46c350ef54a7f59dd60bed92ae83"); + + assertSHA1("", "da39a3ee5e6b4b0d3255bfef95601890afd80709"); + assertSHA1("abc", "a9993e364706816aba3e25717850c26c9cd0d89d"); + assertSHA1("message digest", "c12252ceda8be8994d5fa0290a47231c1d16aae3"); + assertSHA1( + "abcdefghijklmnopqrstuvwxyz", + "32d10c7b8cf96570ca04ce37f2a19d84240d3a89"); + assertSHA1( + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", + "761c457bf73b14d27e9e9265c46f4b4dda11f940"); + assertSHA1( + "12345678901234567890123456789012345678901234567890123456789012345678901234567890", + "50abf5706a150990a08b2c5ea40fa0e585554732"); +} + + void RegisterSuite_Signature() { RegisterTest("Signature", "Basic", TestSignatureBasic); @@ -431,4 +513,6 @@ void RegisterSuite_Signature() RegisterTest("Signature", "SHA1", TestSHA1); RegisterTest("Signature", "HAVAL", TestHAVAL); RegisterTest("Signature", "ArchiveSigGen", TestArchiveSigGen); + RegisterTest("Signature", "RFC1321", TestRFC1321); + RegisterTest("Signature", "RFC3174", TestRFC3174); } From e74d916a0975e40f6049d0e7b7c55d323eb4f688 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Mon, 4 Sep 2017 15:37:07 -0700 Subject: [PATCH 27/29] Rename misspelled crytpo_t.cpp -> crypto_t.cpp --- src/twtest/Makefile.am | 2 +- src/twtest/Makefile.in | 4 ++-- src/twtest/{crytpo_t.cpp => crypto_t.cpp} | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename src/twtest/{crytpo_t.cpp => crypto_t.cpp} (100%) diff --git a/src/twtest/Makefile.am b/src/twtest/Makefile.am index 662f936..cedcf10 100644 --- a/src/twtest/Makefile.am +++ b/src/twtest/Makefile.am @@ -19,7 +19,7 @@ cmdlineparser_t.cpp \ codeconvert_t.cpp \ configfile_t.cpp \ cryptoarchive_t.cpp \ -crytpo_t.cpp \ +crypto_t.cpp \ dbdatasource_t.cpp \ debug_t.cpp \ displayencoder_t.cpp \ diff --git a/src/twtest/Makefile.in b/src/twtest/Makefile.in index f3ee9b4..409d2bd 100644 --- a/src/twtest/Makefile.in +++ b/src/twtest/Makefile.in @@ -109,7 +109,7 @@ am_twtest_OBJECTS = archive_t.$(OBJEXT) blockfile_t.$(OBJEXT) \ blockrecordarray_t.$(OBJEXT) charutil_t.$(OBJEXT) \ cmdlineparser_t.$(OBJEXT) codeconvert_t.$(OBJEXT) \ configfile_t.$(OBJEXT) cryptoarchive_t.$(OBJEXT) \ - crytpo_t.$(OBJEXT) dbdatasource_t.$(OBJEXT) debug_t.$(OBJEXT) \ + crypto_t.$(OBJEXT) dbdatasource_t.$(OBJEXT) debug_t.$(OBJEXT) \ displayencoder_t.$(OBJEXT) error_t.$(OBJEXT) \ errorbucketimpl_t.$(OBJEXT) fcocompare_t.$(OBJEXT) \ fcodatabasefile_t.$(OBJEXT) fconame_t.$(OBJEXT) \ @@ -360,7 +360,7 @@ cmdlineparser_t.cpp \ codeconvert_t.cpp \ configfile_t.cpp \ cryptoarchive_t.cpp \ -crytpo_t.cpp \ +crypto_t.cpp \ dbdatasource_t.cpp \ debug_t.cpp \ displayencoder_t.cpp \ diff --git a/src/twtest/crytpo_t.cpp b/src/twtest/crypto_t.cpp similarity index 100% rename from src/twtest/crytpo_t.cpp rename to src/twtest/crypto_t.cpp From 1566771be0c9b8d11f011be6c49258e92401b991 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Mon, 4 Sep 2017 17:24:47 -0700 Subject: [PATCH 28/29] Tweak install.sh slightly so you can optionally run it standalone instead of thru make install, & add a custom install dir param to it. --- installer/install.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/installer/install.sh b/installer/install.sh index 3492ccd..178731c 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -28,7 +28,7 @@ fi ## The usage message. ##------------------------------------------------------- -USAGE="install.sh [] [-n] [-f] [-s ] [-l ]" +USAGE="install.sh [] [-n] [-f] [-s ] [-l ] [-d ]" ##------------------------------------------------------- ## Figure out how to do an echo without newline. @@ -104,8 +104,10 @@ fi ## Miscellaneous configuration parameters. ##------------------------------------------------------- -# prefix -prefix="${prefix:=/usr}" +# set a few location variables if caller didn't pass them to us +prefix="${prefix:=/usr/local}" +sysconfdir="${sysconfdir:=/usr/local/etc}" +path_to_vi="${path_to_vi:=/usr/bin/vi}" # License File name TWLICENSEFILE="COPYING" @@ -178,6 +180,13 @@ while [ "x$1" != "x" ] ; do exit 1 ;; *) TW_LOCAL_PASS="$2"; shift ;; esac ;; + -d) case "$2" in + "" | -*) + echo "Error: missing install dir with -d option." 1>&2 + echo "$USAGE" + exit 1 ;; + *) prefix="$2"; sysconfdir="$2/bin"; shift ;; + esac ;; -*) echo "Error: unknown argument $1" 1>&2 echo "$USAGE" exit 1 ;; From a56bae53977178e4b3eb7c47f22f2e97be3441e4 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Tue, 5 Sep 2017 19:14:27 -0700 Subject: [PATCH 29/29] Only use /dev/urandom if --enable-urandom configure arg is used, since current impl falls over on HP-UX & Solaris 10 SPARC & possibly elsewhere --- config.h.in | 3 +++ configure | 14 ++++++++++++++ configure.ac | 6 ++++++ src/core/platform.h | 2 ++ src/twcrypto/crypto.cpp | 4 ++-- src/twtest/platform_t.cpp | 2 +- 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/config.h.in b/config.h.in index 184a9f7..616429f 100644 --- a/config.h.in +++ b/config.h.in @@ -6,6 +6,9 @@ /* Compile with debug code */ #undef DEBUG +/* Enable use of /dev/urandom */ +#undef ENABLE_DEV_URANDOM + /* this is the prefix for STL exception functions */ #undef EXCEPTION_NAMESPACE diff --git a/configure b/configure index 5c6690e..f08717a 100755 --- a/configure +++ b/configure @@ -752,6 +752,7 @@ enable_static enable_debug enable_coverage enable_profiling +enable_urandom enable_dependency_tracking enable_commoncrypto enable_iconv @@ -1399,6 +1400,7 @@ Optional Features: --enable-debug compile with debuging enabled --enable-coverage enable code coverage --enable-profiling enable profiling + --enable-urandom use /dev/urandom --enable-dependency-tracking do not reject slow dependency extractors --disable-dependency-tracking @@ -3525,6 +3527,18 @@ then LDFLAGS="${LDFLAGS} -pg" fi +# Check whether --enable-urandom was given. +if test "${enable_urandom+set}" = set; then : + enableval=$enable_urandom; +fi + +if test "x$enable_urandom" = xyes +then + +$as_echo "#define ENABLE_DEV_URANDOM 1" >>confdefs.h + +fi + ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' diff --git a/configure.ac b/configure.ac index 8b995a8..3cc105e 100644 --- a/configure.ac +++ b/configure.ac @@ -60,6 +60,12 @@ then LDFLAGS="${LDFLAGS} -pg" fi +AC_ARG_ENABLE(urandom, [ --enable-urandom use /dev/urandom]) +if test "x$enable_urandom" = xyes +then + AC_DEFINE(ENABLE_DEV_URANDOM, 1, [Enable use of /dev/urandom]) +fi + dnl ################### dnl Checks for programs dnl ################### diff --git a/src/core/platform.h b/src/core/platform.h index 7a5ffcf..56155be 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -320,6 +320,8 @@ // which uses this syntax for UNC paths. So we'll allow leading double slashes there, but // continue removing them on all other platforms +#define USE_DEV_URANDOM (HAVE_DEV_URANDOM && ENABLE_DEV_URANDOM) + //============================================================================= // Miscellaneous // diff --git a/src/twcrypto/crypto.cpp b/src/twcrypto/crypto.cpp index a5efe74..0334555 100644 --- a/src/twcrypto/crypto.cpp +++ b/src/twcrypto/crypto.cpp @@ -1241,7 +1241,7 @@ cHashedKey192::~cHashedKey192() ///////////////////////////////////////////////////////// -#if HAVE_DEV_URANDOM +#if USE_DEV_URANDOM static bool randomize_by_device(const char* device_name, int8* destbuf, int len) { static int rng_device = -1; @@ -1267,7 +1267,7 @@ static bool gRandomizeBytesSeeded = false; void RandomizeBytes(int8* destbuf, int len) { -#if HAVE_DEV_URANDOM +#if USE_DEV_URANDOM if (randomize_by_device("/dev/urandom", destbuf, len)) return; diff --git a/src/twtest/platform_t.cpp b/src/twtest/platform_t.cpp index bf63b62..b9b96b0 100644 --- a/src/twtest/platform_t.cpp +++ b/src/twtest/platform_t.cpp @@ -91,7 +91,7 @@ AlignMe::AlignMe() // to have any need for that behavior, which begs the question of why // this test exists in the first place. // -bcox -#if (!IS_HPUX) +#if (!IS_HPUX && !IS_SOLARIS) //Turns out Solaris SPARC is unhappy with this test too, btw TCOUT << _T("Testing alignment of size ") << ALIGN_SIZE << std::endl; // access a double in the byte array to see if it is aligned. if it isn't and the CPU