Skip to contentSkip to conversation

test: Add missing test-statx test case

PATCH In review Philip Lorenz 2 participants 3 messages Aug 11, 2021 – Aug 15, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test: Add missing test-statx test case

Adding this test case was erroneously omitted in
7c722296879906fe093e1e7c4b7537e150d492cd.

---
 test/test-statx.c  | 20 ++++++++++++++++++++
 test/test-statx.sh |  6 ++++++
 2 files changed, 26 insertions(+)
 create mode 100644 test/test-statx.c
 create mode 100755 test/test-statx.sh
test/test-statx.c new file +20 -0
new file mode 100644
index 0000000..06d86af
@@ -0,0 +1,20 @@
+/*
+ * Test that passing NULL to a parameter marked as nonnull works correctly
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ */
+#define _GNU_SOURCE
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+// Passing a null pointer is the test scenario
+#pragma GCC diagnostic ignored "-Wnonnull"
+
+int main(void) {
+    if (statx(0, NULL, 0, 0, NULL) != -1) {
+        return 1;
+    }
+    return 0;
+}
test/test-statx.sh new file +6 -0
new file mode 100755
index 0000000..77d0302
@@ -0,0 +1,6 @@
+#!/bin/bash
+#
+# SPDX-License-Identifier: LGPL-2.1-only
+#
+
+exec ./test/test-statx
Signature · 1 line
2.32.0
#1 lore raw
Quoted 56 lines · Philip Lorenz

Adding this test case was erroneously omitted in
7c722296879906fe093e1e7c4b7537e150d492cd.

---
 test/test-statx.c  | 20 ++++++++++++++++++++
 test/test-statx.sh |  6 ++++++
 2 files changed, 26 insertions(+)
 create mode 100644 test/test-statx.c
 create mode 100755 test/test-statx.sh
test/test-statx.c new file +20 -0
new file mode 100644
index 0000000..06d86af
@@ -0,0 +1,20 @@
+/*
+ * Test that passing NULL to a parameter marked as nonnull works correctly
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ */
+#define _GNU_SOURCE
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+// Passing a null pointer is the test scenario
+#pragma GCC diagnostic ignored "-Wnonnull"
+
+int main(void) {
+    if (statx(0, NULL, 0, 0, NULL) != -1) {
+        return 1;
+    }
+    return 0;
+}
test/test-statx.sh new file +6 -0
new file mode 100755
index 0000000..77d0302
@@ -0,0 +1,6 @@
+#!/bin/bash
+#
+# SPDX-License-Identifier: LGPL-2.1-only
+#
+
+exec ./test/test-statx
Signature · 1 line
2.32.0

Applying this patch (along with <[email protected]>) makes all the tests pass for me. However, the run of test-statx.sh causes:

couldn't allocate absolute path for '(null)'.

to be printed.

Thanks.

Mike.

#2 lore raw
Quoted 55 lines · Mike Crowe
Quoted 51 lines · Philip Lorenz

Adding this test case was erroneously omitted in
7c722296879906fe093e1e7c4b7537e150d492cd.

---
  test/test-statx.c  | 20 ++++++++++++++++++++
  test/test-statx.sh |  6 ++++++
  2 files changed, 26 insertions(+)

create mode 100644 test/test-statx.c
create mode 100755 test/test-statx.sh

test/test-statx.c new file +20 -0
new file mode 100644
index 0000000..06d86af
@@ -0,0 +1,20 @@
+/*
+ * Test that passing NULL to a parameter marked as nonnull works correctly
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ */
+#define _GNU_SOURCE
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+// Passing a null pointer is the test scenario
+#pragma GCC diagnostic ignored "-Wnonnull"
+
+int main(void) {
+    if (statx(0, NULL, 0, 0, NULL) != -1) {
+        return 1;
+    }
+    return 0;
+}
test/test-statx.sh new file +6 -0
new file mode 100755
index 0000000..77d0302
@@ -0,0 +1,6 @@
+#!/bin/bash
+#
+# SPDX-License-Identifier: LGPL-2.1-only
+#
+
+exec ./test/test-statx
Signature · 1 line
2.32.0

Applying this patch (along with <[email protected]>) makes all the tests pass for me. However, the run of test-statx.sh causes:

Quoted 3 lines

couldn't allocate absolute path for '(null)'.

to be printed.

The test explicitly tests whether a NULL path does not segfault when compiled with newer GCC releases (which was fixed in 7c722296879906fe093e1e7c4b7537e150d492cd). As such the observed error message is "intended". It may however make sense to special case NULL parameters in pseudo_root_path.

Philip