a453f5b98e8f31889cde087403395d672f9df698Michael Graff/*
81baaebbc7734a717058f253853361a4fd3b2078Tinderbox User * Copyright (C) 2000, 2001, 2004, 2007, 2015-2017 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
a453f5b98e8f31889cde087403395d672f9df698Michael Graff */
a453f5b98e8f31889cde087403395d672f9df698Michael Graff
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater/* $Id: driver.c,v 1.11 2007/06/19 23:47:00 tbox Exp $ */
a453f5b98e8f31889cde087403395d672f9df698Michael Graff
ae302c18c296f31c02efb613887f206894caa749David Lawrence#include <config.h>
a453f5b98e8f31889cde087403395d672f9df698Michael Graff
a453f5b98e8f31889cde087403395d672f9df698Michael Graff#include <stdlib.h>
a453f5b98e8f31889cde087403395d672f9df698Michael Graff#include <stdio.h>
a453f5b98e8f31889cde087403395d672f9df698Michael Graff#include <time.h>
a453f5b98e8f31889cde087403395d672f9df698Michael Graff
4162d3b36d1a3c25724c7e37ce839f67b2352bbbMark Andrews#include <isc/platform.h>
3759f10fc543747668b1ca4b4671f35b0dea8445Francis Dupont#include <isc/print.h>
ae302c18c296f31c02efb613887f206894caa749David Lawrence#include <isc/string.h>
ae302c18c296f31c02efb613887f206894caa749David Lawrence#include <isc/util.h>
ae302c18c296f31c02efb613887f206894caa749David Lawrence
a453f5b98e8f31889cde087403395d672f9df698Michael Graff#include "driver.h"
a453f5b98e8f31889cde087403395d672f9df698Michael Graff
a453f5b98e8f31889cde087403395d672f9df698Michael Graff#include "testsuite.h"
a453f5b98e8f31889cde087403395d672f9df698Michael Graff
a453f5b98e8f31889cde087403395d672f9df698Michael Graff#define NTESTS (sizeof(tests) / sizeof(test_t))
a453f5b98e8f31889cde087403395d672f9df698Michael Graff
a453f5b98e8f31889cde087403395d672f9df698Michael Graffconst char *gettime(void);
a453f5b98e8f31889cde087403395d672f9df698Michael Graffconst char *test_result_totext(test_result_t);
a453f5b98e8f31889cde087403395d672f9df698Michael Graff
a453f5b98e8f31889cde087403395d672f9df698Michael Graffconst char *
a453f5b98e8f31889cde087403395d672f9df698Michael Graffgettime(void) {
a453f5b98e8f31889cde087403395d672f9df698Michael Graff static char now[512];
a453f5b98e8f31889cde087403395d672f9df698Michael Graff time_t t;
4162d3b36d1a3c25724c7e37ce839f67b2352bbbMark Andrews#if defined(ISC_PLATFORM_USETHREADS) && !defined(WIN32)
4162d3b36d1a3c25724c7e37ce839f67b2352bbbMark Andrews struct tm tm;
4162d3b36d1a3c25724c7e37ce839f67b2352bbbMark Andrews#endif
a453f5b98e8f31889cde087403395d672f9df698Michael Graff
a453f5b98e8f31889cde087403395d672f9df698Michael Graff (void)time(&t);
a453f5b98e8f31889cde087403395d672f9df698Michael Graff
4162d3b36d1a3c25724c7e37ce839f67b2352bbbMark Andrews#if defined(ISC_PLATFORM_USETHREADS) && !defined(WIN32)
4162d3b36d1a3c25724c7e37ce839f67b2352bbbMark Andrews strftime(now, sizeof(now) - 1, "%A %d %B %H:%M:%S %Y",
4162d3b36d1a3c25724c7e37ce839f67b2352bbbMark Andrews localtime_r(&t, &tm));
4162d3b36d1a3c25724c7e37ce839f67b2352bbbMark Andrews#else
4162d3b36d1a3c25724c7e37ce839f67b2352bbbMark Andrews strftime(now, sizeof(now) - 1, "%A %d %B %H:%M:%S %Y", localtime(&t));
4162d3b36d1a3c25724c7e37ce839f67b2352bbbMark Andrews#endif
a453f5b98e8f31889cde087403395d672f9df698Michael Graff
a453f5b98e8f31889cde087403395d672f9df698Michael Graff return (now);
a453f5b98e8f31889cde087403395d672f9df698Michael Graff}
a453f5b98e8f31889cde087403395d672f9df698Michael Graff
a453f5b98e8f31889cde087403395d672f9df698Michael Graffconst char *
a453f5b98e8f31889cde087403395d672f9df698Michael Grafftest_result_totext(test_result_t result) {
a453f5b98e8f31889cde087403395d672f9df698Michael Graff const char *s;
a453f5b98e8f31889cde087403395d672f9df698Michael Graff switch (result) {
a453f5b98e8f31889cde087403395d672f9df698Michael Graff case PASSED:
5f6f061e40e5ec48dd42d3329bfe9d56730efe56Michael Graff s = "PASS";
a453f5b98e8f31889cde087403395d672f9df698Michael Graff break;
a453f5b98e8f31889cde087403395d672f9df698Michael Graff case FAILED:
5f6f061e40e5ec48dd42d3329bfe9d56730efe56Michael Graff s = "FAIL";
a453f5b98e8f31889cde087403395d672f9df698Michael Graff break;
a453f5b98e8f31889cde087403395d672f9df698Michael Graff case UNTESTED:
a453f5b98e8f31889cde087403395d672f9df698Michael Graff s = "UNTESTED";
a453f5b98e8f31889cde087403395d672f9df698Michael Graff break;
a453f5b98e8f31889cde087403395d672f9df698Michael Graff case UNKNOWN:
a453f5b98e8f31889cde087403395d672f9df698Michael Graff default:
a453f5b98e8f31889cde087403395d672f9df698Michael Graff s = "UNKNOWN";
a453f5b98e8f31889cde087403395d672f9df698Michael Graff break;
a453f5b98e8f31889cde087403395d672f9df698Michael Graff }
a453f5b98e8f31889cde087403395d672f9df698Michael Graff
a453f5b98e8f31889cde087403395d672f9df698Michael Graff return (s);
a453f5b98e8f31889cde087403395d672f9df698Michael Graff}
a453f5b98e8f31889cde087403395d672f9df698Michael Graff
a453f5b98e8f31889cde087403395d672f9df698Michael Graffint
a453f5b98e8f31889cde087403395d672f9df698Michael Graffmain(int argc, char **argv) {
a453f5b98e8f31889cde087403395d672f9df698Michael Graff test_t *test;
a453f5b98e8f31889cde087403395d672f9df698Michael Graff test_result_t result;
a453f5b98e8f31889cde087403395d672f9df698Michael Graff unsigned int n_failed;
a453f5b98e8f31889cde087403395d672f9df698Michael Graff unsigned int testno;
a453f5b98e8f31889cde087403395d672f9df698Michael Graff
a453f5b98e8f31889cde087403395d672f9df698Michael Graff UNUSED(argc);
a453f5b98e8f31889cde087403395d672f9df698Michael Graff UNUSED(argv);
a453f5b98e8f31889cde087403395d672f9df698Michael Graff
a453f5b98e8f31889cde087403395d672f9df698Michael Graff printf("S:%s:%s\n", SUITENAME, gettime());
a453f5b98e8f31889cde087403395d672f9df698Michael Graff
a453f5b98e8f31889cde087403395d672f9df698Michael Graff n_failed = 0;
f1b68725503ff3e46001eee5a1751e29a43a09d1Andreas Gustafsson for (testno = 0; testno < NTESTS; testno++) {
a453f5b98e8f31889cde087403395d672f9df698Michael Graff test = &tests[testno];
a453f5b98e8f31889cde087403395d672f9df698Michael Graff printf("T:%s:%u:A\n", test->tag, testno + 1);
a453f5b98e8f31889cde087403395d672f9df698Michael Graff printf("A:%s\n", test->description);
a453f5b98e8f31889cde087403395d672f9df698Michael Graff result = test->func();
a453f5b98e8f31889cde087403395d672f9df698Michael Graff printf("R:%s\n", test_result_totext(result));
a453f5b98e8f31889cde087403395d672f9df698Michael Graff if (result != PASSED)
a453f5b98e8f31889cde087403395d672f9df698Michael Graff n_failed++;
a453f5b98e8f31889cde087403395d672f9df698Michael Graff }
a453f5b98e8f31889cde087403395d672f9df698Michael Graff
a453f5b98e8f31889cde087403395d672f9df698Michael Graff printf("E:%s:%s\n", SUITENAME, gettime());
a453f5b98e8f31889cde087403395d672f9df698Michael Graff
a453f5b98e8f31889cde087403395d672f9df698Michael Graff if (n_failed > 0)
a453f5b98e8f31889cde087403395d672f9df698Michael Graff exit(1);
41c2511119fa8ce79e76de63b6ca65b381d34c52David Lawrence
41c2511119fa8ce79e76de63b6ca65b381d34c52David Lawrence return (0);
a453f5b98e8f31889cde087403395d672f9df698Michael Graff}
a453f5b98e8f31889cde087403395d672f9df698Michael Graff