Migrate a couple more tests from the old regress structure to atf
This commit is contained in:
parent
736ce759b3
commit
95456adcc6
@ -1,4 +1,4 @@
|
||||
# $NetBSD: mi,v 1.185 2010/12/21 18:05:43 njoly Exp $
|
||||
# $NetBSD: mi,v 1.186 2010/12/22 23:45:44 pgoyette Exp $
|
||||
#
|
||||
# Note: don't delete entries from here - mark them as "obsolete" instead.
|
||||
#
|
||||
@ -318,6 +318,7 @@
|
||||
./usr/libdata/debug/usr/tests/lib/csu/h_initfini3.debug tests-lib-debug debug,atf
|
||||
./usr/libdata/debug/usr/tests/lib/libc tests-lib-debug
|
||||
./usr/libdata/debug/usr/tests/lib/libc/gen tests-lib-debug
|
||||
./usr/libdata/debug/usr/tests/lib/libc/gen/t_basedirname.debug tests-lib-debug debug,atf
|
||||
./usr/libdata/debug/usr/tests/lib/libc/gen/t_glob_star.debug tests-lib-debug debug,atf
|
||||
./usr/libdata/debug/usr/tests/lib/libc/gen/t_syslog_pthread.debug tests-lib-debug debug,atf
|
||||
./usr/libdata/debug/usr/tests/lib/libc/hash tests-lib-debug
|
||||
@ -1533,8 +1534,9 @@
|
||||
./usr/tests/lib/libc/Atffile tests-lib-tests atf
|
||||
./usr/tests/lib/libc/gen tests-lib-tests
|
||||
./usr/tests/lib/libc/gen/Atffile tests-lib-tests atf
|
||||
./usr/tests/lib/libc/gen/t_basedirname tests-lib-tests atf
|
||||
./usr/tests/lib/libc/gen/t_glob_star tests-lib-tests atf
|
||||
./usr/tests/lib/libc/gen/t_syslog_pthread tests-lib-tests atf
|
||||
./usr/tests/lib/libc/gen/t_syslog_pthread tests-lib-tests atf
|
||||
./usr/tests/lib/libc/hash tests-lib-tests
|
||||
./usr/tests/lib/libc/hash/Atffile tests-lib-tests atf
|
||||
./usr/tests/lib/libc/hash/t_sha2 tests-lib-tests atf
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile,v 1.2 2010/12/17 19:12:30 pooka Exp $
|
||||
# $NetBSD: Makefile,v 1.3 2010/12/22 23:45:44 pgoyette Exp $
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
@ -6,6 +6,7 @@ TESTSDIR= ${TESTSBASE}/lib/libc/gen
|
||||
|
||||
TESTS_C+= t_glob_star
|
||||
TESTS_C+= t_syslog_pthread
|
||||
TESTS_C+= t_basedirname
|
||||
|
||||
LDADD.t_syslog_pthread+=-lpthread
|
||||
|
||||
|
202
tests/lib/libc/gen/t_basedirname.c
Normal file
202
tests/lib/libc/gen/t_basedirname.c
Normal file
@ -0,0 +1,202 @@
|
||||
/* $NetBSD: t_basedirname.c,v 1.1 2010/12/22 23:45:44 pgoyette Exp $ */
|
||||
|
||||
/*
|
||||
* Regression test for basename(3).
|
||||
*
|
||||
* Written by Jason R. Thorpe <thorpej@NetBSD.org>, Oct. 2002.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#include <atf-c.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <libgen.h>
|
||||
|
||||
struct {
|
||||
const char *input;
|
||||
const char *output;
|
||||
} test_basename_table[] = {
|
||||
/*
|
||||
* The following are taken from the "Sample Input and Output Strings
|
||||
* for basename()" table in IEEE Std 1003.1-2001.
|
||||
*/
|
||||
{ "/usr/lib", "lib" },
|
||||
{ "/usr/", "usr" },
|
||||
{ "/", "/" },
|
||||
{ "///", "/" },
|
||||
{ "//usr//lib//", "lib" },
|
||||
/*
|
||||
* IEEE Std 1003.1-2001:
|
||||
*
|
||||
* If path is a null pointer or points to an empty string,
|
||||
* basename() shall return a pointer to the string "." .
|
||||
*/
|
||||
{ "", "." },
|
||||
{ NULL, "." },
|
||||
/*
|
||||
* IEEE Std 1003.1-2001:
|
||||
*
|
||||
* If the string is exactly "//", it is implementation-defined
|
||||
* whether "/" or "//" is returned.
|
||||
*
|
||||
* The NetBSD implementation returns "/".
|
||||
*/
|
||||
{ "//", "/" },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
struct {
|
||||
const char *input;
|
||||
const char *output;
|
||||
} test_dirname_table[] = {
|
||||
/*
|
||||
* The following are taken from the "Sample Input and Output Strings
|
||||
* for dirname()" table in IEEE Std 1003.1-2001.
|
||||
*/
|
||||
{ "/usr/lib", "/usr" },
|
||||
{ "/usr/", "/" },
|
||||
{ "usr", "." },
|
||||
{ "/", "/" },
|
||||
{ ".", "." },
|
||||
{ "..", "." },
|
||||
/*
|
||||
* IEEE Std 1003.1-2001:
|
||||
*
|
||||
* If path is a null pointer or points to an empty string,
|
||||
* dirname() shall return a pointer to the string "." .
|
||||
*/
|
||||
{ "", "." },
|
||||
{ NULL, "." },
|
||||
/*
|
||||
* IEEE Std 1003.1-2001:
|
||||
*
|
||||
* Since the meaning of the leading "//" is implementation-defined,
|
||||
* dirname("//foo") may return either "//" or "/" (but nothing else).
|
||||
*
|
||||
* The NetBSD implementation returns "/".
|
||||
*/
|
||||
{ "//foo", "/" },
|
||||
/*
|
||||
* Make sure the trailing slashes after the directory name component
|
||||
* get trimmed. The Std does not talk about this, but this is what
|
||||
* Solaris 8's dirname(3) does.
|
||||
*/
|
||||
{ "/usr///lib", "/usr" },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
ATF_TC(t_basename);
|
||||
|
||||
ATF_TC_HEAD(t_basename, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test basename(3) with POSIX examples");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(t_basename, tc)
|
||||
{
|
||||
char testbuf[32], *base;
|
||||
int i;
|
||||
|
||||
for (i = 0; test_basename_table[i].output != NULL; i++) {
|
||||
if (test_basename_table[i].input != NULL) {
|
||||
if (strlen(test_basename_table[i].input) >=
|
||||
sizeof(testbuf))
|
||||
atf_tc_skip("Testbuf too small!");
|
||||
strcpy(testbuf, test_basename_table[i].input);
|
||||
base = basename(testbuf);
|
||||
} else
|
||||
base = basename(NULL);
|
||||
|
||||
/*
|
||||
* basename(3) is allowed to modify the input buffer.
|
||||
* However, that is considered hostile by some programs,
|
||||
* and so we elect to consider this an error.
|
||||
*
|
||||
* This is not a problem, as basename(3) is also allowed
|
||||
* to return a pointer to a statically-allocated buffer
|
||||
* (it is explicitly not required to be reentrant).
|
||||
*/
|
||||
if (test_basename_table[i].input != NULL &&
|
||||
strcmp(test_basename_table[i].input, testbuf) != 0) {
|
||||
fprintf(stderr,
|
||||
"Input buffer for \"%s\" was modified\n",
|
||||
test_basename_table[i].input);
|
||||
atf_tc_fail("Input buffer was modified.");
|
||||
}
|
||||
|
||||
/* Make sure the result is correct. */
|
||||
if (strcmp(test_basename_table[i].output, base) != 0) {
|
||||
fprintf(stderr,
|
||||
"Input \"%s\", output \"%s\", expected \"%s\"\n",
|
||||
test_basename_table[i].input ==
|
||||
NULL ? "(null)" : test_basename_table[i].input,
|
||||
base, test_basename_table[i].output);
|
||||
atf_tc_fail("Output does not match expected value.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ATF_TC(t_dirname);
|
||||
|
||||
ATF_TC_HEAD(t_dirname, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test dirname(3) with POSIX examples");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(t_dirname, tc)
|
||||
{
|
||||
char testbuf[32], *base;
|
||||
int i;
|
||||
|
||||
for (i = 0; test_dirname_table[i].output != NULL; i++) {
|
||||
if (test_dirname_table[i].input != NULL) {
|
||||
if (strlen(test_dirname_table[i].input) >=
|
||||
sizeof(testbuf))
|
||||
atf_tc_skip("Testbuf too small!");
|
||||
strcpy(testbuf, test_dirname_table[i].input);
|
||||
base = dirname(testbuf);
|
||||
} else
|
||||
base = dirname(NULL);
|
||||
|
||||
/*
|
||||
* dirname(3) is allowed to modify the input buffer.
|
||||
* However, that is considered hostile by some programs,
|
||||
* and so we elect to consider this an error.
|
||||
*
|
||||
* This is not a problem, as dirname(3) is also allowed
|
||||
* to return a pointer to a statically-allocated buffer
|
||||
* (it is explicitly not required to be reentrant).
|
||||
*/
|
||||
if (test_dirname_table[i].input != NULL &&
|
||||
strcmp(test_dirname_table[i].input, testbuf) != 0) {
|
||||
fprintf(stderr,
|
||||
"Input buffer for \"%s\" was modified\n",
|
||||
test_dirname_table[i].input);
|
||||
atf_tc_fail("Input buffer was modified.");
|
||||
}
|
||||
|
||||
/* Make sure the result is correct. */
|
||||
if (strcmp(test_dirname_table[i].output, base) != 0) {
|
||||
fprintf(stderr,
|
||||
"Input \"%s\", output \"%s\", expected \"%s\"\n",
|
||||
test_dirname_table[i].input ==
|
||||
NULL ? "(null)" : test_dirname_table[i].input,
|
||||
base, test_dirname_table[i].output);
|
||||
atf_tc_fail("Output does not match expected value.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
ATF_TP_ADD_TC(tp, t_basename);
|
||||
ATF_TP_ADD_TC(tp, t_dirname);
|
||||
|
||||
return atf_no_error();
|
||||
}
|
Loading…
Reference in New Issue
Block a user