[BACK]Return to t_fifos.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / tests / fs / ffs

File: [cvs.NetBSD.org] / src / tests / fs / ffs / t_fifos.c (download)

Revision 1.5, Sun Nov 7 17:51:17 2010 UTC (10 years, 5 months ago) by jmmv
Branch: MAIN
CVS Tags: yamt-pagecache-tag8, yamt-pagecache-base9, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, yamt-pagecache-base3, yamt-pagecache-base2, yamt-pagecache-base, yamt-pagecache, tls-maxphys-base, tls-maxphys, tls-earlyentropy-base, tls-earlyentropy, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, pgoyette-localcount-base, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, netbsd-6-base, netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, netbsd-6, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus, matt-mips64-premerge-20101231, localcount-20160914, cherry-xenmp-base, cherry-xenmp, bouyer-quota2-nbase, bouyer-quota2-base, bouyer-quota2, agc-symver-base, agc-symver
Branch point for: pgoyette-localcount
Changes since 1.4: +1 -2 lines

Adjusts tests after import of atf-0.12:

- The use.fs property is gone.
- Mark the tests/fs/t_create:attrs test as broken when using the default
  unprivileged-user:_atf setting.  This probably deserves a fix somehow
  but I'm not sure at this point.

/*	$NetBSD: t_fifos.c,v 1.5 2010/11/07 17:51:17 jmmv Exp $	*/

#include <sys/types.h>
#include <sys/mount.h>

#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include <rump/rump.h>
#include <rump/rump_syscalls.h>

#include <ufs/ufs/ufsmount.h>

#include "../../h_macros.h"

ATF_TC_HEAD(fifos, tc)
	atf_tc_set_md_var(tc, "descr", "test fifo support in ffs");
	atf_tc_set_md_var(tc, "timeout", "5");

#define teststr1 "raving & drooling"
#define teststr2 "haha, charade"

static void *
w1(void *arg)
	int fd;

	fd = rump_sys_open("sheep", O_WRONLY);
	if (fd == -1)
		atf_tc_fail_errno("w1 open");
	if (rump_sys_write(fd, teststr1, sizeof(teststr1)) != sizeof(teststr1))
		atf_tc_fail_errno("w1 write");

	return NULL;

static void *
w2(void *arg)
	int fd;

	fd = rump_sys_open("pigs", O_WRONLY);
	if (fd == -1)
		atf_tc_fail_errno("w2 open");
	if (rump_sys_write(fd, teststr2, sizeof(teststr2)) != sizeof(teststr2))
		atf_tc_fail_errno("w2 write");

	return NULL;

static void *
r1(void *arg)
	char buf[32];
	int fd;

	fd = rump_sys_open("sheep", O_RDONLY);
	if (fd == -1)
		atf_tc_fail_errno("r1 open");
	if (rump_sys_read(fd, buf, sizeof(buf)) != sizeof(teststr1))
		atf_tc_fail_errno("r1 read");

	if (strcmp(teststr1, buf) != 0)
		atf_tc_fail("got invalid str, %s vs. %s", buf, teststr1);

	return NULL;

static void *
r2(void *arg)
	char buf[32];
	int fd;

	fd = rump_sys_open("pigs", O_RDONLY);
	if (fd == -1)
		atf_tc_fail_errno("r2 open");
	if (rump_sys_read(fd, buf, sizeof(buf)) != sizeof(teststr2))
		atf_tc_fail_errno("r2 read");

	if (strcmp(teststr2, buf) != 0)
		atf_tc_fail("got invalid str, %s vs. %s", buf, teststr2);

	return NULL;

#define IMGNAME "atf.img"

const char *newfs = "newfs -F -s 10000 " IMGNAME;
#define FAKEBLK "/dev/sp00ka"

ATF_TC_BODY(fifos, tc)
	struct ufs_args args;
	pthread_t ptw1, ptw2, ptr1, ptr2;

	if (system(newfs) == -1)
		atf_tc_fail_errno("newfs failed");

	memset(&args, 0, sizeof(args));
	args.fspec = __UNCONST(FAKEBLK);

	if (rump_sys_mkdir("/animals", 0777) == -1)
		atf_tc_fail_errno("cannot create mountpoint");
	rump_pub_etfs_register(FAKEBLK, IMGNAME, RUMP_ETFS_BLK);
	if (rump_sys_mount(MOUNT_FFS, "/animals", 0, &args, sizeof(args))==-1)
		atf_tc_fail_errno("rump_sys_mount failed");

	/* create fifos */
	if (rump_sys_chdir("/animals") == 1)
	if (rump_sys_mkfifo("pigs", S_IFIFO | 0777) == -1)
	if (rump_sys_mkfifo("sheep", S_IFIFO | 0777) == -1)
	pthread_create(&ptw1, NULL, w1, NULL);
	pthread_create(&ptw2, NULL, w2, NULL);
	pthread_create(&ptr1, NULL, r1, NULL);
	pthread_create(&ptr2, NULL, r2, NULL);

	pthread_join(ptw1, NULL);
	pthread_join(ptw2, NULL);
	pthread_join(ptr1, NULL);
	pthread_join(ptr2, NULL);

	if (rump_sys_chdir("/") == 1)

	if (rump_sys_unmount("/animals", 0) == -1)
		atf_tc_fail_errno("unmount failed");

ATF_TC_CLEANUP(fifos, tc)


	ATF_TP_ADD_TC(tp, fifos);
	return 0;