Esempio n. 1
0
ATF_TC_BODY(fork, tc)
{
    fprintf(stdout, "Should not get into child\n");
    fprintf(stderr, "Should not get into child\n");
    pid_t pid = atf_utils_fork();
    if (pid == 0) {
        fprintf(stdout, "Child stdout\n");
        fprintf(stderr, "Child stderr\n");
        exit(EXIT_SUCCESS);
    }

    int status;
    ATF_REQUIRE(waitpid(pid, &status, 0) != -1);
    ATF_REQUIRE(WIFEXITED(status));
    ATF_REQUIRE_EQ(EXIT_SUCCESS, WEXITSTATUS(status));

    atf_dynstr_t out_name;
    RE(atf_dynstr_init_fmt(&out_name, "atf_utils_fork_%d_out.txt", (int)pid));
    atf_dynstr_t err_name;
    RE(atf_dynstr_init_fmt(&err_name, "atf_utils_fork_%d_err.txt", (int)pid));

    char buffer[1024];
    read_file(atf_dynstr_cstring(&out_name), buffer, sizeof(buffer));
    ATF_REQUIRE_STREQ("Child stdout\n", buffer);
    read_file(atf_dynstr_cstring(&err_name), buffer, sizeof(buffer));
    ATF_REQUIRE_STREQ("Child stderr\n", buffer);

    atf_dynstr_fini(&err_name);
    atf_dynstr_fini(&out_name);
}
Esempio n. 2
0
ATF_TC_BODY(pkgdb_get_virtualpkg_test, tc)
{
	xbps_dictionary_t pkgd;
	struct xbps_handle xh;
	const char *tcsdir, *pkgver;

	/* get test source dir */
	tcsdir = atf_tc_get_config_var(tc, "srcdir");

	memset(&xh, 0, sizeof(xh));
	strncpy(xh.rootdir, tcsdir, sizeof(xh.rootdir));
	strncpy(xh.metadir, tcsdir, sizeof(xh.metadir));
	xh.flags = XBPS_FLAG_DEBUG;
	ATF_REQUIRE_EQ(xbps_init(&xh), 0);

	pkgd = xbps_pkgdb_get_virtualpkg(&xh, "mixed");
	ATF_REQUIRE_EQ(xbps_object_type(pkgd), XBPS_TYPE_DICTIONARY);
	xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
	ATF_REQUIRE_STREQ(pkgver, "virtual-mixed-0.1_1");

	pkgd = xbps_pkgdb_get_virtualpkg(&xh, "mixed>0");
	ATF_REQUIRE_EQ(xbps_object_type(pkgd), XBPS_TYPE_DICTIONARY);
	xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
	ATF_REQUIRE_STREQ(pkgver, "virtual-mixed-0.1_1");

	pkgd = xbps_pkgdb_get_virtualpkg(&xh, "mixed<2");
	ATF_REQUIRE_EQ(xbps_object_type(pkgd), XBPS_TYPE_DICTIONARY);
	xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
	ATF_REQUIRE_STREQ(pkgver, "virtual-mixed-0.1_1");

	pkgd = xbps_pkgdb_get_virtualpkg(&xh, "mixed-0.1_1");
	ATF_REQUIRE_EQ(xbps_object_type(pkgd), XBPS_TYPE_DICTIONARY);
	xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
	ATF_REQUIRE_STREQ(pkgver, "virtual-mixed-0.1_1");
}
ATF_TC_BODY(sdl_print, tc)
{
	char buf[1024];
	char res[1024];
	int r, e;
	size_t l = sizeof(buf);
	struct sockaddr_dl sdl;

	memset(&sdl, 0, sizeof(sdl));
	for (size_t i = 0; i < __arraycount(tst); i++) {
		memcpy(&sdl.sdl_addr, &tst[i].ia, sizeof(sdl.sdl_addr));
		sdl.sdl_index = (uint16_t)i;
		r = sdl_print(buf, l, &sdl);
		e = snprintf(res, l, "[%s]:%zu", tst[i].str, i);
		ATF_REQUIRE_STREQ(buf, res);
		ATF_REQUIRE_EQ(r, e);
	}

	l = 8;
	for (size_t i = 0; i < __arraycount(tst); i++) {
		memcpy(&sdl.sdl_addr, &tst[i].ia, sizeof(sdl.sdl_addr));
		sdl.sdl_index = (uint16_t)i;
		r = sdl_print(buf, l, &sdl);
		e = snprintf(res, l, "[%s]:%zu", tst[i].str, i);
		ATF_REQUIRE_STREQ(buf, res);
		ATF_REQUIRE_EQ(r, e);
	}
}
Esempio n. 4
0
ATF_TC_BODY(readline__some, tc)
{
    const char *l1 = "First line with % formatting % characters %";
    const char *l2 = "Second line; much longer than the first one";
    const char *l3 = "Last line, without terminator";

    atf_utils_create_file("test.txt", "%s\n%s\n%s", l1, l2, l3);

    const int fd = open("test.txt", O_RDONLY);
    ATF_REQUIRE(fd != -1);

    char *line;

    line = atf_utils_readline(fd);
    ATF_REQUIRE_STREQ(l1, line);
    free(line);

    line = atf_utils_readline(fd);
    ATF_REQUIRE_STREQ(l2, line);
    free(line);

    line = atf_utils_readline(fd);
    ATF_REQUIRE_STREQ(l3, line);
    free(line);

    close(fd);
}
Esempio n. 5
0
ATF_TC_BODY(reregister_reg, tc)
{
	char buf[1024];
	int localfd, etcfd;
	ssize_t n;
	int tfd;

	etcfd = open("/etc/passwd", O_RDONLY);
	ATF_REQUIRE(etcfd != -1);

	localfd = open("./testfile", O_RDWR | O_CREAT, 0666);
	ATF_REQUIRE(localfd != -1);

	ATF_REQUIRE_EQ(write(localfd, TESTSTR1, TESTSTR1SZ), TESTSTR1SZ);
	/* testfile now contains test string */

	rump_init();

	ATF_REQUIRE_EQ(rump_pub_etfs_register(TESTPATH1, "/etc/passwd",
	    RUMP_ETFS_REG), 0);
	tfd = rump_sys_open(TESTPATH1, O_RDONLY);
	ATF_REQUIRE(tfd != -1);
	ATF_REQUIRE(rump_sys_read(tfd, buf, sizeof(buf)) > 0);
	rump_sys_close(tfd);
	rump_pub_etfs_remove(TESTPATH1);

	ATF_REQUIRE_EQ(rump_pub_etfs_register(TESTPATH2, "./testfile",
	    RUMP_ETFS_REG), 0);
	tfd = rump_sys_open(TESTPATH2, O_RDWR);
	ATF_REQUIRE(tfd != -1);
	memset(buf, 0, sizeof(buf));
	ATF_REQUIRE((n = rump_sys_read(tfd, buf, sizeof(buf))) > 0);

	/* check that we have what we expected */
	ATF_REQUIRE_STREQ(buf, TESTSTR1);

	/* ... while here, check that writing works too */
	ATF_REQUIRE_EQ(rump_sys_lseek(tfd, 0, SEEK_SET), 0);
	ATF_REQUIRE(TESTSTR1SZ <= TESTSTR2SZ);
	ATF_REQUIRE_EQ(rump_sys_write(tfd, TESTSTR2, TESTSTR2SZ), TESTSTR2SZ);

	memset(buf, 0, sizeof(buf));
	ATF_REQUIRE_EQ(lseek(localfd, 0, SEEK_SET), 0);
	ATF_REQUIRE(read(localfd, buf, sizeof(buf)) > 0);
	ATF_REQUIRE_STREQ(buf, TESTSTR2);
	close(etcfd);
	close(localfd);
}
Esempio n. 6
0
ATF_TC_BODY(find_all_orphans_test, tc)
{
	struct xbps_handle xh;
	xbps_array_t res;
	xbps_dictionary_t pkgd;
	xbps_string_t pstr;
	const char *pkgver, *tcsdir;
	unsigned int i;

	/* get test source dir */
	tcsdir = atf_tc_get_config_var(tc, "srcdir");

	memset(&xh, 0, sizeof(xh));
	xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir));
	xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir));
	ATF_REQUIRE_EQ(xbps_init(&xh), 0);

	pstr = xbps_string_create();
	res = xbps_find_pkg_orphans(&xh, NULL);
	for (i = 0; i < xbps_array_count(res); i++) {
		pkgd = xbps_array_get(res, i);
		xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
		xbps_string_append_cstring(pstr, pkgver);
		xbps_string_append_cstring(pstr, "\n");
	}
	printf("%s", xbps_string_cstring_nocopy(pstr));

	ATF_REQUIRE_STREQ(xbps_string_cstring_nocopy(pstr), expected_output_all);
}
Esempio n. 7
0
ATF_TC_BODY(vprintf__empty, tc)
{
    char* buffer;
    kyua_error_t error = call_vprintf(&buffer, "%s", "");
    ATF_REQUIRE(!kyua_error_is_set(error));
    ATF_REQUIRE_STREQ("", buffer);
}
Esempio n. 8
0
ATF_TC_BODY(mbsnrtowcs, tc)
{
	size_t i;
	const struct test *t;
	mbstate_t state;
	wchar_t buf[64];
	const char *src;
	size_t len;

	for (i = 0; i < __arraycount(tests); ++i) {
		t = &tests[i];
		ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C");
		ATF_REQUIRE(setlocale(LC_CTYPE, t->locale) != NULL);
		memset(&state, 0, sizeof(state));
		src = t->data;
		len = mbsnrtowcs(buf, &src, t->limit,
		    __arraycount(buf), &state);
		ATF_REQUIRE_EQ(src, t->data + t->limit);
		ATF_REQUIRE_EQ(len, t->output1_len);
		ATF_REQUIRE(wmemcmp(t->output1, buf, len) == 0);
		len = mbsnrtowcs(buf, &src, strlen(src) + 1,
		    __arraycount(buf), &state);
		ATF_REQUIRE_EQ(len, strlen(t->data) - t->limit);
		ATF_REQUIRE(wmemcmp(t->output2, buf, len + 1) == 0);
		ATF_REQUIRE_EQ(src, NULL);
	}
}
Esempio n. 9
0
ATF_TC_BODY(concat__two, tc)
{
    char* path;
    ATF_REQUIRE(!kyua_error_is_set(kyua_fs_concat(&path, "foo", "bar", NULL)));
    ATF_REQUIRE_STREQ("foo/bar", path);
    free(path);
}
Esempio n. 10
0
ATF_TC_BODY(pkgdb_get_pkg_revdeps_test, tc)
{
	struct xbps_handle xh;
	xbps_array_t res;
	xbps_string_t pstr;
	const char *tcsdir, *str;
	const char *eout = "four-0.1_1\ntwo-0.1_1\n";
	unsigned int i;

	/* get test source dir */
	tcsdir = atf_tc_get_config_var(tc, "srcdir");

	memset(&xh, 0, sizeof(xh));
	strncpy(xh.rootdir, tcsdir, sizeof(xh.rootdir));
	strncpy(xh.metadir, tcsdir, sizeof(xh.metadir));
	xh.flags = XBPS_FLAG_DEBUG;
	ATF_REQUIRE_EQ(xbps_init(&xh), 0);

	res = xbps_pkgdb_get_pkg_revdeps(&xh, "mixed");
	ATF_REQUIRE_EQ(xbps_object_type(res), XBPS_TYPE_ARRAY);

	pstr = xbps_string_create();
	for (i = 0; i < xbps_array_count(res); i++) {
		xbps_array_get_cstring_nocopy(res, i, &str);
		xbps_string_append_cstring(pstr, str);
		xbps_string_append_cstring(pstr, "\n");
	}
	ATF_REQUIRE_STREQ(xbps_string_cstring_nocopy(pstr), eout);
}
Esempio n. 11
0
ATF_TC_BODY(make_absolute__absolute, tc)
{
    char* absolute;
    ATF_REQUIRE(!kyua_error_is_set(kyua_fs_make_absolute(
                                       "/this/is/absolute", &absolute)));
    ATF_REQUIRE_STREQ("/this/is/absolute", absolute);
    free(absolute);
}
Esempio n. 12
0
ATF_TC_BODY(concat__several, tc)
{
    char* path;
    ATF_REQUIRE(!kyua_error_is_set(kyua_fs_concat(&path, "/usr", ".", "bin",
                                   "ls", NULL)));
    ATF_REQUIRE_STREQ("/usr/./bin/ls", path);
    free(path);
}
Esempio n. 13
0
ATF_TC_BODY(create_file, tc)
{
    atf_utils_create_file("test.txt", "This is a test with %d", 12345);

    char buffer[128];
    read_file("test.txt", buffer, sizeof(buffer));
    ATF_REQUIRE_STREQ("This is a test with 12345", buffer);
}
Esempio n. 14
0
ATF_TC_BODY(usage_error_format__args, tc)
{
    kyua_error_t error = kyua_usage_error_new("%s message %d", "A", 123);
    char buffer[1024];
    kyua_error_format(error, buffer, sizeof(buffer));
    ATF_REQUIRE_STREQ("A message 123", buffer);
    kyua_error_free(error);
}
Esempio n. 15
0
ATF_TC_BODY(oom_error_format, tc)
{
    kyua_error_t error = kyua_oom_error_new();
    char buffer[1024];
    kyua_error_format(error, buffer, sizeof(buffer));
    ATF_REQUIRE_STREQ("Not enough memory", buffer);
    kyua_error_free(error);
}
Esempio n. 16
0
ATF_TC_BODY(usage_error_format__plain, tc)
{
    kyua_error_t error = kyua_usage_error_new("Test message");
    char buffer[1024];
    kyua_error_format(error, buffer, sizeof(buffer));
    ATF_REQUIRE_STREQ("Test message", buffer);
    kyua_error_free(error);
}
Esempio n. 17
0
ATF_TC_BODY(error_format__default, tc)
{
    kyua_error_t error = kyua_error_new("test_error", NULL, 0, NULL);
    char buffer[1024];
    kyua_error_format(error, buffer, sizeof(buffer));
    ATF_REQUIRE_STREQ("Error 'test_error'", buffer);
    kyua_error_free(error);
}
Esempio n. 18
0
ATF_TC_BODY(vprintf__some, tc)
{
    char* buffer;
    kyua_error_t error = call_vprintf(&buffer, "this is %d %s", 123, "foo");
    ATF_REQUIRE(!kyua_error_is_set(error));
    ATF_REQUIRE_STREQ("this is 123 foo", buffer);
    free(buffer);
}
Esempio n. 19
0
static void
h_mbtowc(const char *locale, const char *illegal, const char *legal)
{
	char buf[64];
	size_t stateful, ret;
	char *str;

	ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C");
#ifdef __NetBSD__
	ATF_REQUIRE(setlocale(LC_CTYPE, locale) != NULL);
#else
	if (setlocale(LC_CTYPE, locale) == NULL) {
		fprintf(stderr, "Locale %s not found.\n", locale);
		return;
	}
#endif

	ATF_REQUIRE((str = setlocale(LC_ALL, NULL)) != NULL);
	(void)printf("Using locale: %s\n", str);

	stateful = wctomb(NULL, L'\0');
	(void)printf("Locale is state-%sdependent\n",
		stateful ? "in" : "");

	/* initialize internal state */
	ret = mbtowc(NULL, NULL, 0);
	ATF_REQUIRE(stateful ? ret : !ret);

	(void)strvis(buf, illegal, VIS_WHITE | VIS_OCTAL);
	(void)printf("Checking illegal sequence: \"%s\"\n", buf);

	ret = mbtowc(NULL, illegal, strlen(illegal));
	(void)printf("mbtowc() returned: %zd\n", ret);
	ATF_REQUIRE_EQ(ret, (size_t)-1);
	(void)printf("errno: %s\n", strerror(errno));
	ATF_REQUIRE_EQ(errno, EILSEQ);

	/* if this is stateless encoding, this re-initialization is not required. */
	if (stateful) {
		/* re-initialize internal state */
		ret = mbtowc(NULL, NULL, 0);
		ATF_REQUIRE(stateful ? ret : !ret);
	}

	/* valid multibyte sequence case */
	(void)strvis(buf, legal, VIS_WHITE | VIS_OCTAL);
	(void)printf("Checking legal sequence: \"%s\"\n", buf);

	errno = 0;
	ret = mbtowc(NULL, legal, strlen(legal));
	(void)printf("mbtowc() returned: %zd\n", ret);
	ATF_REQUIRE(ret != (size_t)-1);
	(void)printf("errno: %s\n", strerror(errno));
	ATF_REQUIRE_EQ(errno, 0);

	(void)printf("Ok.\n");
}
Esempio n. 20
0
ATF_TC_BODY(check_files, tc)
{
	FILE *f;
	unsigned char *sum;

	f = fopen("foo", "w");
	fprintf(f, "bar\n");
	fclose(f);

	sum = pkg_checksum_file("foo", PKG_HASH_TYPE_SHA256_HEX);
	ATF_REQUIRE_STREQ(sum, "7d865e959b2466918c9863afca942d0fb89d7c9ac0c99bafc3749504ded97730");

	ATF_CHECK(pkg_checksum_validate_file("foo", "7d865e959b2466918c9863afca942d0fb89d7c9ac0c99bafc3749504ded97730") == 0);
	free(sum);

	sum=pkg_checksum_generate_file("foo", PKG_HASH_TYPE_SHA256_HEX);
	ATF_REQUIRE_STREQ(sum, "1$7d865e959b2466918c9863afca942d0fb89d7c9ac0c99bafc3749504ded97730");
}
Esempio n. 21
0
ATF_TC_BODY(error_format__custom__ok, tc)
{
    kyua_error_t error = kyua_error_new("test_error", NULL, 0, test_format);
    const char* exp_message = "Test formatting function";
    char buffer[1024];
    ATF_REQUIRE_EQ((int)strlen(exp_message),
                   kyua_error_format(error, buffer, sizeof(buffer)));
    ATF_REQUIRE_STREQ(exp_message, buffer);
    kyua_error_free(error);
}
Esempio n. 22
0
ATF_TC_BODY(run_params_init__defaults, tc)
{
    kyua_run_params_t run_params;
    kyua_run_params_init(&run_params);

    ATF_REQUIRE_EQ(60, run_params.timeout_seconds);
    ATF_REQUIRE_EQ(getuid(), run_params.unprivileged_user);
    ATF_REQUIRE_EQ(getgid(), run_params.unprivileged_group);
    ATF_REQUIRE_STREQ(".", run_params.work_directory);
}
Esempio n. 23
0
ATF_TC_BODY(redirect__other, tc)
{
    const char *message = "Foo bar\nbaz\n";
    atf_utils_redirect(15, "captured.txt");
    ATF_REQUIRE(write(15, message, strlen(message)) != -1);
    close(15);

    char buffer[1024];
    read_file("captured.txt", buffer, sizeof(buffer));
    ATF_REQUIRE_STREQ(message, buffer);
}
Esempio n. 24
0
ATF_TC_BODY(redirect__stderr, tc)
{
    fprintf(stderr, "Buffer this");
    atf_utils_redirect(STDERR_FILENO, "captured.txt");
    fprintf(stderr, "The printed message");
    fflush(stderr);

    char buffer[1024];
    read_file("captured.txt", buffer, sizeof(buffer));
    ATF_REQUIRE_STREQ("The printed message", buffer);
}
Esempio n. 25
0
ATF_TC_BODY(fgets_error__unexpected_eof, tc)
{
    atf_utils_create_file("test.txt", "Some line\n");

    char buffer[1024];
    FILE* input = fopen("test.txt", "r");

    ATF_REQUIRE(kyua_text_fgets_no_newline(buffer, sizeof(buffer), input)
                == buffer);
    ATF_REQUIRE_STREQ("Some line", buffer);

    ATF_REQUIRE(kyua_text_fgets_no_newline(buffer, sizeof(buffer), input)
                == NULL);
    kyua_error_t error = kyua_text_fgets_error(input, "Foo bar");
    ATF_REQUIRE(kyua_error_is_set(error));
    kyua_error_format(error, buffer, sizeof(buffer));
    ATF_REQUIRE_STREQ("Foo bar: unexpected EOF", buffer);
    kyua_error_free(error);

    fclose(input);
}
Esempio n. 26
0
ATF_TC_BODY(cat_file__several_lines, tc)
{
    atf_utils_create_file("file.txt", "First\nSecond line\nAnd third\n");
    atf_utils_redirect(STDOUT_FILENO, "captured.txt");
    atf_utils_cat_file("file.txt", ">");
    fflush(stdout);
    close(STDOUT_FILENO);

    char buffer[1024];
    read_file("captured.txt", buffer, sizeof(buffer));
    ATF_REQUIRE_STREQ(">First\n>Second line\n>And third\n", buffer);
}
Esempio n. 27
0
ATF_TC_BODY(cat_file__one_line, tc)
{
    atf_utils_create_file("file.txt", "This is a single line\n");
    atf_utils_redirect(STDOUT_FILENO, "captured.txt");
    atf_utils_cat_file("file.txt", "PREFIX");
    fflush(stdout);
    close(STDOUT_FILENO);

    char buffer[1024];
    read_file("captured.txt", buffer, sizeof(buffer));
    ATF_REQUIRE_STREQ("PREFIXThis is a single line\n", buffer);
}
Esempio n. 28
0
ATF_TC_BODY(cat_file__empty, tc)
{
    atf_utils_create_file("file.txt", "%s", "");
    atf_utils_redirect(STDOUT_FILENO, "captured.txt");
    atf_utils_cat_file("file.txt", "PREFIX");
    fflush(stdout);
    close(STDOUT_FILENO);

    char buffer[1024];
    read_file("captured.txt", buffer, sizeof(buffer));
    ATF_REQUIRE_STREQ("", buffer);
}
Esempio n. 29
0
ATF_TC_BODY(cat_file__no_newline_eof, tc)
{
    atf_utils_create_file("file.txt", "Foo\n bar baz");
    atf_utils_redirect(STDOUT_FILENO, "captured.txt");
    atf_utils_cat_file("file.txt", "PREFIX");
    fflush(stdout);
    close(STDOUT_FILENO);

    char buffer[1024];
    read_file("captured.txt", buffer, sizeof(buffer));
    ATF_REQUIRE_STREQ("PREFIXFoo\nPREFIX bar baz", buffer);
}
Esempio n. 30
0
ATF_TC_BODY(fork, tc)
{
    fprintf(stdout, "Should not get into child\n");
    fprintf(stderr, "Should not get into child\n");
    pid_t pid = atf_utils_fork();
    if (pid == 0) {
        fprintf(stdout, "Child stdout\n");
        fprintf(stderr, "Child stderr\n");
        exit(EXIT_SUCCESS);
    }

    int status;
    ATF_REQUIRE(waitpid(pid, &status, 0) != -1);
    ATF_REQUIRE(WIFEXITED(status));
    ATF_REQUIRE_EQ(EXIT_SUCCESS, WEXITSTATUS(status));

    char buffer[1024];
    read_file("atf_utils_fork_out.txt", buffer, sizeof(buffer));
    ATF_REQUIRE_STREQ("Child stdout\n", buffer);
    read_file("atf_utils_fork_err.txt", buffer, sizeof(buffer));
    ATF_REQUIRE_STREQ("Child stderr\n", buffer);
}