t_mtime_write.c revision 1.1
11.1Smartin/*-
21.1Smartin * Copyright (c) 2017 The NetBSD Foundation, Inc.
31.1Smartin * All rights reserved.
41.1Smartin *
51.1Smartin * Redistribution and use in source and binary forms, with or without
61.1Smartin * modification, are permitted provided that the following conditions
71.1Smartin * are met:
81.1Smartin * 1. Redistributions of source code must retain the above copyright
91.1Smartin *    notice, this list of conditions and the following disclaimer.
101.1Smartin * 2. Redistributions in binary form must reproduce the above copyright
111.1Smartin *    notice, this list of conditions and the following disclaimer in the
121.1Smartin *    documentation and/or other materials provided with the distribution.
131.1Smartin *
141.1Smartin * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
151.1Smartin * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
161.1Smartin * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
171.1Smartin * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
181.1Smartin * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
191.1Smartin * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
201.1Smartin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
211.1Smartin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
221.1Smartin * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
231.1Smartin * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
241.1Smartin * POSSIBILITY OF SUCH DAMAGE.
251.1Smartin */
261.1Smartin
271.1Smartin#include <sys/cdefs.h>
281.1Smartin__COPYRIGHT("@(#) Copyright (c) 2013\
291.1Smartin The NetBSD Foundation, inc. All rights reserved.");
301.1Smartin__RCSID("$NetBSD: t_mtime_write.c,v 1.1 2017/11/19 21:05:26 martin Exp $");
311.1Smartin
321.1Smartin#include <errno.h>
331.1Smartin#include <unistd.h>
341.1Smartin#include <stdio.h>
351.1Smartin#include <stdlib.h>
361.1Smartin#include <sys/stat.h>
371.1Smartin#include <atf-c.h>
381.1Smartin
391.1Smartin#include <rump/rump_syscalls.h>
401.1Smartin#include <rump/rump.h>
411.1Smartin
421.1Smartin#include "../common/h_fsmacros.h"
431.1Smartin
441.1Smartin#define LOCKFILE	"lock"
451.1Smartin
461.1Smartinstatic time_t
471.1Smartinlock_it(void)
481.1Smartin{
491.1Smartin	struct stat st;
501.1Smartin
511.1Smartin	if (rump_sys_stat(LOCKFILE, &st) != 0)
521.1Smartin		st.st_mtime = 0;
531.1Smartin
541.1Smartin	int f = rump_sys_open(LOCKFILE, O_WRONLY|O_CREAT, 0666);
551.1Smartin	if (f == -1) return 0;
561.1Smartin	rump_sys_write(f, &st, sizeof st);
571.1Smartin	rump_sys_close(f);
581.1Smartin
591.1Smartin	return st.st_mtime;
601.1Smartin}
611.1Smartin
621.1Smartinstatic void
631.1Smartinmtime_update_on_write(const atf_tc_t *tc, const char *path)
641.1Smartin{
651.1Smartin	time_t last_ts = 0;
661.1Smartin	int res;
671.1Smartin
681.1Smartin	/* atf_tc_expect_fail("PR kern/52738"); */
691.1Smartin
701.1Smartin	res = rump_sys_chdir(path);
711.1Smartin	if (res == -1)
721.1Smartin		atf_tc_fail("chdir failed");
731.1Smartin
741.1Smartin	for (int i = 0; i < 5; i++) {
751.1Smartin		time_t l = lock_it();
761.1Smartin		printf("last lock: %ld\n", (long)l);
771.1Smartin		ATF_REQUIRE_MSG(i == 0 || l > last_ts,
781.1Smartin		    "iteration %d: lock time did not increase, old time %lu, "
791.1Smartin		    "new time %lu", i,
801.1Smartin		    (unsigned long)last_ts, (unsigned long)l);
811.1Smartin		last_ts = l;
821.1Smartin		sleep(2);
831.1Smartin	}
841.1Smartin	rump_sys_chdir("/");
851.1Smartin}
861.1Smartin
871.1SmartinATF_FSAPPLY(mtime_update_on_write, "Checks for mtime updates by writing (PR kern/52738)");
88