Skip to content

Commit

Permalink
Tests: Created tests for hardware functions.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JiaT75 authored and Larhzu committed Jun 10, 2022
1 parent 5c8ffdc commit aa75c55
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/Makefile.am
Expand Up @@ -39,6 +39,7 @@ LDADD += $(LTLIBINTL)
check_PROGRAMS = \
create_compress_files \
test_check \
test_hardware \
test_stream_flags \
test_filter_flags \
test_block_header \
Expand All @@ -47,6 +48,7 @@ check_PROGRAMS = \

TESTS = \
test_check \
test_hardware \
test_stream_flags \
test_filter_flags \
test_block_header \
Expand Down
45 changes: 45 additions & 0 deletions 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();
}

2 comments on commit aa75c55

@aureliancnx
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The beginning of the backdoor man.

@Lewiscowles1986
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.