File: test_touch

package info (click to toggle)
disorderfs 0.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 208 kB
  • sloc: cpp: 482; sh: 156; makefile: 61
file content (57 lines) | stat: -rwxr-xr-x 1,297 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh
# Test for https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=911281

. ./common

Mount

EXPECTED_HUMAN="1970-05-23T21:21:18.000Z"
EXPECTED="12345678"
FILENAME="target/a"

# $1 = 'a' for access time OR 'm' for modified time
Expect() {
	cat > ${TEMPDIR}/test_touch.c <<EOF
#include <stdio.h>
#include <sys/stat.h>

int main(void) {
	struct stat st;

	if (stat("${FILENAME}", &st) == -1) {
		fprintf(stderr, "ERROR: could not stat '${FILENAME}'\n");
		return 1;
	}

	if (st.st_${1}tim.tv_sec != ${EXPECTED}) {
		fprintf(stderr, "ASSERTION FAILED: ${1}time result=%ld != expected=${EXPECTED}\n",
			st.st_${1}tim.tv_sec);
		return 1;
	}

	return 0;
}
EOF
	cc -Wall -Werror -pedantic -o ${TEMPDIR}/test_touch ${TEMPDIR}/test_touch.c || \
		Fail "Could not compile test_touch.c testcase"
	${TEMPDIR}/test_touch
}

TEMPDIR="$(mktemp -d -t test_touch.XXXXXXXXXX)"
trap "Unmount 2>/dev/null; rm -rf ${TEMPDIR}" EXIT

touch ${FILENAME}
touch -d ${EXPECTED_HUMAN} ${FILENAME}
Expect m || Fail "test1: mtime"
Expect a || Fail "test1: atime"

# This is what tar xf does for extracted files via futimens(2)
touch ${FILENAME}
touch -m -d ${EXPECTED_HUMAN} ${FILENAME}
Expect m || Fail "test2: mtime"

touch ${FILENAME}
touch -a -d ${EXPECTED_HUMAN} ${FILENAME}
Expect a || Fail "test3: atime"

Unmount