[packages/test/cryptsetup-debug] cryptsetup test failure debug

atler atler at pld-linux.org
Mon Feb 5 03:36:22 CET 2024


commit 18f2389e2e2a9ed5dad8fd320bebdce042a78277
Author: Jan Palus <atler at pld-linux.org>
Date:   Mon Feb 5 01:46:47 2024 +0100

    cryptsetup test failure debug

 test.c    | 37 +++++++++++++++++++++++++++++++++++++
 test.spec |  8 ++++++--
 2 files changed, 43 insertions(+), 2 deletions(-)
---
diff --git a/test.spec b/test.spec
index 2c55129..69c0f00 100644
--- a/test.spec
+++ b/test.spec
@@ -9,8 +9,8 @@ Version:	1
 Release:	7
 License:	GPL
 Group:		Applications/System
-Source0:	http://execve.pl/u/u?r=23#/xxx
-# Source0-md5:	6de9439834c9147569741d3c9c9fc010
+Source0:	test.c
+# Source0-md5:	144269a4ffe67704e0b71fb8d91fabe9
 URL:		http://www.pld-linux.org/
 #BuildArch:	noarch
 BuildRoot:	%{tmpdir}/%{name}-%{version}-root-%(id -u -n)
@@ -21,6 +21,10 @@ testing something.
 %prep
 %setup -qcT
 
+%{__cc} -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 %{SOURCE0} -o test
+strace ./test
+test $(sha256sum file-normal|cut -f1 -d' ') = $(sha256sum file-direct-io|cut -f1 -d' ')
+
 %install
 rm -rf $RPM_BUILD_ROOT
 install -d $RPM_BUILD_ROOT
diff --git a/test.c b/test.c
new file mode 100644
index 0000000..4c34780
--- /dev/null
+++ b/test.c
@@ -0,0 +1,37 @@
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define BUF_SIZE 1048576
+
+int write_all(int fd, void* buf, size_t count) {
+  int ret;
+  int to_write = count;
+  do {
+    ret = write(fd, buf, to_write);
+  } while (ret >= 0 && (to_write -= ret) > 0);
+
+  return ret < 0 ? ret : count;
+}
+
+void write_file(char* name, int adflags) {
+  char *buf;
+  posix_memalign((void**)&buf, 4096, BUF_SIZE);
+  memset(buf,0xff,BUF_SIZE);
+  int fd = open(name, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR);
+  for (int i = 0; i < 8; i++) {
+    write_all(fd, buf, BUF_SIZE);
+  }
+  close(fd);
+  fd = open(name, O_WRONLY|adflags);
+  lseek(fd, BUF_SIZE, SEEK_SET);
+  memset(buf,0,BUF_SIZE);
+  write_all(fd, buf, BUF_SIZE);
+  close(fd);
+}
+
+int main() {
+  write_file("file-normal", 0);
+  write_file("file-direct-io", O_DIRECT);
+}
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/test.git/commitdiff/18f2389e2e2a9ed5dad8fd320bebdce042a78277



More information about the pld-cvs-commit mailing list