test.c revision a734c64bff58bda2fa48c2795453e092167b0ff7
/*
* Copyright (C) 2011 Michael Brown <mbrown@fensystems.co.uk>.
*
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or 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, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/** @file
*
* Self-test infrastructure
*
*/
/* Forcibly enable assertions */
#include <stddef.h>
#include <stdio.h>
#include <errno.h>
#include <assert.h>
/** Current self-test set */
static struct self_test *current_tests;
/**
* Report test result
*
* @v success Test succeeded
* @v file Test code file
* @v line Test code line
*/
/* Sanity check */
/* Increment test counter */
current_tests->total++;
/* Report failure if applicable */
if ( ! success ) {
printf ( "FAILURE: \"%s\" test failed at %s line %d\n",
}
}
/**
* Run self-test set
*
*/
unsigned int old_assertion_failures = assertion_failures;
/* Sanity check */
/* Record current test set */
/* Run tests */
/* Clear current test set */
/* Record number of assertion failures */
/* Print test set summary */
printf ( "FAILURE: \"%s\" %d of %d tests failed",
if ( tests->assertion_failures ) {
printf ( " with %d assertion failures",
}
printf ( "\n" );
} else {
printf ( "OK: \"%s\" %d tests passed\n",
}
}
/**
* Run all self-tests
*
* @ret rc Return status code
*/
static int run_all_tests ( void ) {
unsigned int failures = 0;
unsigned int assertions = 0;
unsigned int total = 0;
/* Run all compiled-in self-tests */
printf ( "Starting self-tests\n" );
/* Print overall summary */
}
if ( failures || assertions ) {
printf ( "FAILURE: %d of %d tests failed",
if ( assertions ) {
}
printf ( "\n" );
return -EINPROGRESS;
} else {
return 0;
}
}
return -ENOTTY;
}
return run_all_tests();
}
static struct image_type test_image_type = {
.name = "self-tests",
.exec = test_image_exec,
};
static struct image test_image = {
.name = "<TESTS>",
.type = &test_image_type,
};
static void test_init ( void ) {
int rc;
/* Register self-tests image */
DBG ( "Could not register self-test image: %s\n",
/* No way to report failure */
return;
}
}
/** Self-test initialisation function */
.initialise = test_init,
};