FreeBSD/contrib/ntp/sntp/tests/t-log.c
//multiple cleanup_log() causes segfault. Probably the reason it's static. Opening multiple open_logfile(name) will cause segfault x.x I'm guessing it's not intended to be changed. Cleanup after unity test doesn't fix it, looks like. Calling in tearDown() also causes issues.
multiple cleanup_log() causes segfault. Probably the reason it's static. Opening multiple open_logfile(name) will cause segfault x.x I'm guessing it's not intended to be changed. Cleanup after unity test doesn't fix it, looks like. Calling in tearDown() also causes issues.
multiple cleanup_log () causes segfault . Probably the reason it ' s static . Opening multiple open_logfile ( name ) will cause segfault x . x I ' m guessing it ' s not intended to be changed . Cleanup after unity test doesn ' t fix it looks like . Calling in tearDown () also causes issues .
void
testWriteInCustomLogfile(void)
{
	char testString[256] = "12345 ABC";
	char testName[256] = "TEST_PROGNAME3";
	(void)remove("testLogfile2.log");
	sntp_init_logging(testName);
	open_logfile("testLogfile2.log"); 
	msyslog(LOG_ERR, "%s", testString);
	FILE * f = fopen("testLogfile2.log","r");
	char line[256];
	TEST_ASSERT_TRUE( f != NULL);
	while (fgets(line, sizeof(line), f)) {
		printf("%s", line);
	}
	char* x = strstr(line,testName);
	TEST_ASSERT_TRUE( x != NULL);
	x = strstr(line,testString);
	TEST_ASSERT_TRUE( x != NULL);
	fclose(f); 
	return;
}
void testWriteInCustomLogfile ( void ) { char testString [ 256 ] = " " ; char testName [ 256 ] = " " ; ( void ) remove ( " " ) ; sntp_init_logging ( testName ) ; open_logfile ( " " ) ; msyslog ( LOG_ERR , " " , testString ) ; FILE * f = fopen ( " " , " " ) ; char line [ 256 ] ; TEST_ASSERT_TRUE ( f != NULL ) ; while ( fgets ( line , sizeof ( line ) , f ) ) { printf ( " " , line ) ; } char * x = strstr ( line , testName ) ; TEST_ASSERT_TRUE ( x != NULL ) ; x = strstr ( line , testString ) ; TEST_ASSERT_TRUE ( x != NULL ) ; fclose ( f ) ; return ; }
multiple cleanup_log() causes segfault.
multiple cleanup_log () causes segfault .
// ./ causing issues //sntp_init_logging(testName); //should be only 1 line //cleanup_log(); //using this will also cause segfault, because at the end, log.c will  call (using atexit(func) function) cleanup_log(void)-> fclose(syslog_file); //After the 1st fclose, syslog_file = NULL, and is never reset -> hopefully fixed by editing log.c //TEST_ASSERT_EQUAL_STRING(testString,line); //doesn't work, line is dynamic because the process name is random.