[Git][reproducible-builds/disorderfs][master] 2 commits: tests: improve portability
Chris Lamb (@lamby)
gitlab at salsa.debian.org
Sat May 17 16:15:57 UTC 2025
Chris Lamb pushed to branch master at Reproducible Builds / disorderfs
Commits:
065f09a7 by Siva Mahadevan at 2025-05-16T18:06:13-04:00
tests: improve portability
This helps with porting disorderfs to FreeBSD.
- - - - -
c04c8f40 by Chris Lamb at 2025-05-17T16:15:52+00:00
Merge branch 'push-ntslpmkskzxq' into 'master'
tests: improve portability
See merge request reproducible-builds/disorderfs!7
- - - - -
4 changed files:
- disorderfs.cpp
- tests/common
- tests/test_inodes
- tests/test_touch
Changes:
=====================================
disorderfs.cpp
=====================================
@@ -465,7 +465,7 @@ int main (int argc, char** argv)
std::shuffle(dirents.begin(), dirents.end(), g);
}
- for (const auto dirent : dirents) {
+ for (const auto &dirent : dirents) {
st.st_ino = dirent.second;
if (filler(buf, dirent.first.c_str(), &st, 0) != 0) {
return -ENOMEM;
=====================================
tests/common
=====================================
@@ -1,7 +1,6 @@
trap "Unmount 2>/dev/null" EXIT
Mount () {
- Unmount
mkdir -p target
../disorderfs -q "${@}" fixtures/ target/
}
=====================================
tests/test_inodes
=====================================
@@ -9,26 +9,11 @@ trap "Unmount 2>/dev/null; rm -rf ${TEMPDIR}" EXIT
Setup () {
cat >${TEMPDIR}/inodes.cpp <<EOF
#include <dirent.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
#include <sys/stat.h>
-#include <sys/syscall.h>
#include <map>
#include <iostream>
-struct linux_dirent {
- unsigned long d_ino;
- off_t d_off;
- unsigned short d_reclen;
- char d_name[];
-};
-
-#define BUF_SIZE 1024
-
void perror_and_die (const char* s)
{
std::perror(s);
@@ -38,50 +23,44 @@ void perror_and_die (const char* s)
int
main(int argc, char *argv[])
{
- int fd, nread, ret = EXIT_SUCCESS;
- char buf[BUF_SIZE];
+ int ret = EXIT_SUCCESS;
struct stat st;
- const std::string dirname = argc > 1 ? argv[1] : ".";
- struct linux_dirent *d;
std::map<ino_t, std::string> inodes;
+ DIR *dirp;
+ struct dirent *d;
- if ((fd = open(dirname.c_str(), O_RDONLY | O_DIRECTORY)) == -1)
- perror_and_die("open");
+ if ((dirp = opendir("target")) == NULL) perror_and_die("opendir");
- while ((nread = syscall(SYS_getdents, fd, buf, BUF_SIZE)) > 0) {
- for (int pos = 0; pos < nread; pos += d->d_reclen) {
- d = (struct linux_dirent *) (buf + pos);
+ while ((d = readdir(dirp)) != NULL) {
+ const std::string filename = "target/" + std::string(d->d_name);
+ if (stat(filename.c_str(), &st) == -1)
+ perror_and_die("stat");
- std::string filename = dirname + "/" + std::string(d->d_name);
- if (stat(filename.c_str(), &st) == -1)
- perror_and_die("stat");
-
- if (d->d_ino != st.st_ino) {
- std::cerr << filename << ": inode from getdents does not match stat: "
- << d->d_ino << " != " << st.st_ino << std::endl;
- ret = EXIT_FAILURE;
- }
+ if (d->d_ino != st.st_ino) {
+ std::cerr << filename << ": inode from readdir does not match stat: "
+ << d->d_ino << " != " << st.st_ino << std::endl;
+ ret = EXIT_FAILURE;
+ }
- if (inodes.find(d->d_ino) == inodes.end()) {
- inodes[d->d_ino] = filename;
- } else {
- std::cerr << filename << ": duplicate inode: " << d->d_ino
- << " used by " << inodes[d->d_ino] << std::endl;
- ret = EXIT_FAILURE;
- }
+ if (inodes.find(d->d_ino) == inodes.end()) {
+ inodes[d->d_ino] = filename;
+ } else {
+ std::cerr << filename << ": duplicate inode: " << d->d_ino
+ << " used by " << inodes[d->d_ino] << std::endl;
+ ret = EXIT_FAILURE;
}
}
- if (nread == -1)
- perror_and_die("open");
+ if (closedir(dirp) == -1) perror_and_die("closedir");
- exit(ret);
+ return ret;
}
EOF
- g++ -Wall -o${TEMPDIR}/inodes ${TEMPDIR}/inodes.cpp || Fail "Could not compile testcase"
+ c++ -Wall -Werror -pedantic -o${TEMPDIR}/inodes ${TEMPDIR}/inodes.cpp || \
+ Fail "Could not compile testcase"
}
Setup
Mount
-${TEMPDIR}/inodes target || Fail "inodes"
+${TEMPDIR}/inodes || Fail "inodes"
Unmount
=====================================
tests/test_touch
=====================================
@@ -5,32 +5,53 @@
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} ${FILENAME}
-RESULT="$(stat --format=%X-%Y ${FILENAME})"
-if [ "${RESULT}" != "${EXPECTED}-${EXPECTED}" ]
-then
- Fail "test1: Got=${RESULT} Expected=${EXPECTED}"
-fi
+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} ${FILENAME}
-RESULT="$(stat --format=%Y ${FILENAME})"
-if [ "${RESULT}" != "${EXPECTED}" ]
-then
- Fail "test2: Got=${RESULT} Expected=${EXPECTED}"
-fi
+touch -m -d ${EXPECTED_HUMAN} ${FILENAME}
+Expect m || Fail "test2: mtime"
touch ${FILENAME}
-touch -a -d @${EXPECTED} ${FILENAME}
-RESULT="$(stat --format=%X ${FILENAME})"
-if [ "${RESULT}" != "${EXPECTED}" ]
-then
- Fail "test3: Got=${RESULT} Expected=${EXPECTED}"
-fi
+touch -a -d ${EXPECTED_HUMAN} ${FILENAME}
+Expect a || Fail "test3: atime"
Unmount
View it on GitLab: https://salsa.debian.org/reproducible-builds/disorderfs/-/compare/2c3df2235c9c44dde77dd77b47c29ce0e44b36a4...c04c8f40607e154f08c5e0ced5ba91efc1151084
--
View it on GitLab: https://salsa.debian.org/reproducible-builds/disorderfs/-/compare/2c3df2235c9c44dde77dd77b47c29ce0e44b36a4...c04c8f40607e154f08c5e0ced5ba91efc1151084
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20250517/0bc6b23e/attachment.htm>
More information about the rb-commits
mailing list