Skip to content

Commit

Permalink
unit test updates
Browse files Browse the repository at this point in the history
added command line version flag test
updated insertdbgo_xattrs_avail test
valgrind suppressions cleanup
  • Loading branch information
calccrypto committed Feb 14, 2025
1 parent 0de54a6 commit cfa2550
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 29 deletions.
7 changes: 6 additions & 1 deletion src/bf.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ void print_help(const char* prog_name,

// DEBUGGING
void show_input(struct input* in, int retval) {
printf("in.printed_version = %d\n", in->printed_version);
printf("in.printdir = %d\n", in->printdir);
printf("in.buildindex = %d\n", in->buildindex);
printf("in.maxthreads = %zu\n", in->maxthreads);
Expand Down Expand Up @@ -300,7 +301,7 @@ int parse_cmd_line(int argc,
case 'v':
printf(STR(GUFI_VERSION) "\n");
in->printed_version = 1;
return 0;
break;

case 'x': // enable xattr processing
in->process_xattrs = 1;
Expand Down Expand Up @@ -526,6 +527,10 @@ int parse_cmd_line(int argc,
retval = -(in->min_level > in->max_level);
}

if (in->printed_version) {
return -1;
}

// caller requires given number of positional args, after the options.
// <optind> is the number of argv[] values that were recognized as options.
// NOTE: caller may have custom options ovf their own, so returning a
Expand Down
44 changes: 36 additions & 8 deletions test/unit/googletest/bf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ static const std::string exec = "exec"; // argv[0]

static const std::string h = "-h";
static const std::string H = "-H";
static const std::string v = "-v";
static const std::string x = "-x";
static const std::string P = "-P";
static const std::string b = "-b";
Expand Down Expand Up @@ -138,10 +139,12 @@ TEST(input, nullptr) {
EXPECT_NO_THROW(input_fini(nullptr));
}

static void check_input(struct input *in, const bool helped,
static void check_input(struct input *in, const bool helped, const bool version,
const bool flags, const bool options) {
EXPECT_EQ(in->helped, static_cast<int>(helped));

EXPECT_EQ(in->printed_version, version);

EXPECT_EQ(in->process_xattrs, flags);
EXPECT_EQ(in->printdir, flags);
EXPECT_EQ(in->buildindex, flags);
Expand Down Expand Up @@ -253,7 +256,32 @@ TEST(parse_cmd_line, help) {
ASSERT_EQ(dup(fd), STDOUT_FILENO);
EXPECT_EQ(close(fd), 0);

check_input(&in, true, false, false);
check_input(&in, true, false, false, false);

input_fini(&in);
}

TEST(parse_cmd_line, version) {
const char opts[] = "v";

const char *argv[] = {
exec.c_str(),
v.c_str(),
};

int argc = sizeof(argv) / sizeof(argv[0]);

const int fd = dup(STDOUT_FILENO);
ASSERT_NE(fd, -1);
EXPECT_EQ(close(STDOUT_FILENO), 0);;

struct input in;
EXPECT_EQ(parse_cmd_line(argc, (char **) argv, opts, 0, "", &in), -1);

ASSERT_EQ(dup(fd), STDOUT_FILENO);
EXPECT_EQ(close(fd), 0);

check_input(&in, false, true, false, false);

input_fini(&in);
}
Expand Down Expand Up @@ -319,7 +347,7 @@ TEST(parse_cmd_line, debug) {
ASSERT_EQ(dup(fd), STDOUT_FILENO);
EXPECT_EQ(close(fd), 0);

check_input(&in, true, true, true);
check_input(&in, true, false, true, true);

input_fini(&in);
}
Expand Down Expand Up @@ -352,7 +380,7 @@ TEST(parse_cmd_line, flags) {

struct input in;
EXPECT_EQ(parse_cmd_line(argc, (char **) argv, opts, 0, "", &in), argc);
check_input(&in, false, true, false);
check_input(&in, false, false, true, false);

input_fini(&in);
}
Expand Down Expand Up @@ -392,7 +420,7 @@ TEST(parse_cmd_line, options) {

struct input in;
ASSERT_EQ(parse_cmd_line(argc, (char **) argv, opts, 0, "", &in), argc);
check_input(&in, false, false, true);
check_input(&in, false, false, false, true);

input_fini(&in);
}
Expand Down Expand Up @@ -542,7 +570,7 @@ TEST(parse_cmd_line, positional) {
// 1, since no options were read
ASSERT_EQ(parse_cmd_line(argc, (char **) argv, "", 0, "", &in), 1);

check_input(&in, false, false, false);
check_input(&in, false, false, false, false);

input_fini(&in);
}
Expand All @@ -562,7 +590,7 @@ TEST(parse_cmd_line, unused) {
struct input in;
EXPECT_EQ(parse_cmd_line(argc, (char **) argv, opts, 0, "", &in), -1);

check_input(&in, true, false, false);
check_input(&in, true, false, false, false);

input_fini(&in);
}
Expand All @@ -582,7 +610,7 @@ TEST(parse_cmd_line, invalid) {
struct input in;
EXPECT_EQ(parse_cmd_line(argc, (char **) argv, opts, 0, "", &in), -1);

check_input(&in, true, false, false);
check_input(&in, true, false, false, false);

input_fini(&in);
}
Expand Down
2 changes: 2 additions & 0 deletions test/unit/googletest/dbutils.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ TEST(insertdbprep, nullptr) {
TEST(insertdbgo_xattrs_avail, nullptr) {
struct entry_data ed;
memset(&ed, 0, sizeof(ed));
EXPECT_NE(insertdbgo_xattrs_avail(&ed, nullptr), SQLITE_OK);

ed.xattrs.count = 1;
struct xattr xattr;
ed.xattrs.pairs = &xattr;
Expand Down
20 changes: 0 additions & 20 deletions test/unit/googletest/valgrind.suppressions
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,6 @@
fun:_Z13RUN_ALL_TESTSv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:FishyValue
malloc(size)
fun:malloc
fun:realloc
fun:getline_fd
fun:_ZN15getline_fd_Test8TestBodyEv
fun:_ZN7testing8internal38HandleSehExceptionsInMethodIfSupportedINS_4TestEvEET0_PT_MS4_FS3_vEPKc
fun:_ZN7testing8internal35HandleExceptionsInMethodIfSupportedINS_4TestEvEET0_PT_MS4_FS3_vEPKc
fun:_ZN7testing4Test3RunEv
fun:_ZN7testing8TestInfo3RunEv
fun:_ZN7testing9TestSuite3RunEv
fun:_ZN7testing8internal12UnitTestImpl11RunAllTestsEv
fun:_ZN7testing8internal38HandleSehExceptionsInMethodIfSupportedINS0_12UnitTestImplEbEET0_PT_MS4_FS3_vEPKc
fun:_ZN7testing8internal35HandleExceptionsInMethodIfSupportedINS0_12UnitTestImplEbEET0_PT_MS4_FS3_vEPKc
fun:_ZN7testing8UnitTest3RunEv
fun:_Z13RUN_ALL_TESTSv
fun:main
}
{
<insert_a_suppression_name_here>
Memcheck:FishyValue
Expand Down

0 comments on commit cfa2550

Please sign in to comment.