aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJia Tan <jiat0218@gmail.com>2022-06-10 21:35:18 +0800
committerLasse Collin <lasse.collin@tukaani.org>2022-06-10 16:58:47 +0300
commitaa75c5563a760aea3aa23d997d519e702e82726b (patch)
tree6c1219bf5d268cb1be4744a868ae9cfc20035d8d
parentTests: Convert test_check to tuktest. (diff)
downloadxz-aa75c5563a760aea3aa23d997d519e702e82726b.tar.xz
Tests: Created tests for hardware functions.
Created tests for all API functions exported in src/liblzma/api/lzma/hardware.h. The tests are fairly trivial but are helpful because they will inform users if their machines cannot support these functions. They also improve the code coverage metrics.
-rw-r--r--.gitignore1
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/test_hardware.c45
3 files changed, 48 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 11dbc591..ca5f024e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -51,6 +51,7 @@ build-aux/test-driver
/tests/test_block_header
/tests/test_check
/tests/test_filter_flags
+/tests/test_hardware
/tests/test_index
/tests/test_stream_flags
/tests/xzgrep_test_1.xz
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e049add4..ae63f464 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -39,6 +39,7 @@ LDADD += $(LTLIBINTL)
check_PROGRAMS = \
create_compress_files \
test_check \
+ test_hardware \
test_stream_flags \
test_filter_flags \
test_block_header \
@@ -47,6 +48,7 @@ check_PROGRAMS = \
TESTS = \
test_check \
+ test_hardware \
test_stream_flags \
test_filter_flags \
test_block_header \
diff --git a/tests/test_hardware.c b/tests/test_hardware.c
new file mode 100644
index 00000000..34d07892
--- /dev/null
+++ b/tests/test_hardware.c
@@ -0,0 +1,45 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file test_hardware.c
+/// \brief Tests src/liblzma/api/lzma/hardware.h API functions
+///
+/// Since the output values of these functions are hardware dependent, these
+/// tests are trivial. They are simply used to detect errors and machines
+/// that these function are not supported on.
+//
+// Author: Jia Tan
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "tests.h"
+
+
+static void
+test_lzma_physmem(void)
+{
+ // NOTE: Use _skip instead of _fail because 0 can also mean that we
+ // don't know how to get this information on this operating system.
+ if (lzma_physmem() == 0)
+ assert_skip("Could not determine amount of physical memory");
+}
+
+
+static void
+test_lzma_cputhreads(void)
+{
+ if (lzma_cputhreads() == 0)
+ assert_skip("Could not determine cpu core count");
+}
+
+
+extern int
+main(int argc, char **argv)
+{
+ tuktest_start(argc, argv);
+ tuktest_run(test_lzma_physmem);
+ tuktest_run(test_lzma_cputhreads);
+ return tuktest_end();
+}