tests: Add complete suite for cbm_files_match

This is just part of improving coverage within clr-boot-manager, and is
a critical requirement given that we have changed how we determine that
two files differ.

With that said, we still do have the test harness that makes heavy use of
cbm_files_match, and one can clearly see that by deliberately inverting
logic in paths within cbm_files_match, the harness tests then completely
fail.

Signed-off-by: Ikey Doherty <michael.i.doherty@intel.com>
This commit is contained in:
Ikey Doherty
2016-11-07 14:55:00 +00:00
parent ad16443a69
commit 70cc7cda3a
6 changed files with 43 additions and 0 deletions
+4
View File
@@ -7,6 +7,10 @@ EXTRA_DIST = ${top_srcdir}/README.md \
${top_srcdir}/HACKING \
${top_srcdir}/findstatic.pl \
${top_srcdir}/tests/data/blobfile \
${top_srcdir}/tests/data/match \
${top_srcdir}/tests/data/match1 \
${top_srcdir}/tests/data/nomatch1 \
${top_srcdir}/tests/data/nomatch2 \
${top_srcdir}/sgcheck.suppressions \
${top_srcdir}/data/clr-boot-manager-booted.service \
${top_srcdir}/compat/kernel_updater.sh \
+35
View File
@@ -22,6 +22,40 @@
#include "log.h"
#include "nica/files.h"
START_TEST(bootman_match_test)
{
const char *source_match = TOP_DIR "/tests/data/match";
const char *good_match = TOP_DIR "/tests/data/match1";
const char *bad_match_data = TOP_DIR "/tests/data/nomatch1";
const char *bad_match_len = TOP_DIR "/tests/data/nomatch2";
/* In a clean environment, anyway. */
const char *non_exist_path = "PATHTHATWONT@EXIST!";
/* Known good */
fail_if(!cbm_files_match(source_match, good_match), "Known matches failed to match");
/* Known different data */
fail_if(cbm_files_match(source_match, bad_match_data),
"Shouldn't match files with different data");
/* Known different data + length */
fail_if(cbm_files_match(source_match, bad_match_len),
"Shouldn't match files with different length");
/* Known missing target, with source present */
fail_if(cbm_files_match(source_match, non_exist_path),
"Shouldn't match with non existent target");
/* Known missing source with existing target */
fail_if(cbm_files_match(non_exist_path, source_match),
"Shouldn't match with non existent source");
/* Known missing both */
fail_if(cbm_files_match(non_exist_path, non_exist_path),
"Shouldn't match non existent files");
}
END_TEST
START_TEST(bootman_uuid_test)
{
if (geteuid() != 0) {
@@ -70,6 +104,7 @@ static Suite *core_suite(void)
s = suite_create("bootman_files");
tc = tcase_create("bootman_files");
tcase_add_test(tc, bootman_match_test);
tcase_add_test(tc, bootman_uuid_test);
tcase_add_test(tc, bootman_mount_test);
tcase_add_test(tc, bootman_find_boot);
+1
View File
@@ -0,0 +1 @@
This file is for matching.
+1
View File
@@ -0,0 +1 @@
This file is for matching.
+1
View File
@@ -0,0 +1 @@
This file is for matching!
+1
View File
@@ -0,0 +1 @@
This file is for matching. It differs in length