Blame tests/fpgainfo/test_fpgainfo_c.cpp

Packit 534379
// Copyright(c) 2018-2020, Intel Corporation
Packit 534379
//
Packit 534379
// Redistribution  and  use  in source  and  binary  forms,  with  or  without
Packit 534379
// modification, are permitted provided that the following conditions are met:
Packit 534379
//
Packit 534379
// * Redistributions of  source code  must retain the  above copyright notice,
Packit 534379
//   this list of conditions and the following disclaimer.
Packit 534379
// * Redistributions in binary form must reproduce the above copyright notice,
Packit 534379
//   this list of conditions and the following disclaimer in the documentation
Packit 534379
//   and/or other materials provided with the distribution.
Packit 534379
// * Neither the name  of Intel Corporation  nor the names of its contributors
Packit 534379
//   may be used to  endorse or promote  products derived  from this  software
Packit 534379
//   without specific prior written permission.
Packit 534379
//
Packit 534379
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit 534379
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,  BUT NOT LIMITED TO,  THE
Packit 534379
// IMPLIED WARRANTIES OF  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit 534379
// ARE DISCLAIMED.  IN NO EVENT  SHALL THE COPYRIGHT OWNER  OR CONTRIBUTORS BE
Packit 534379
// LIABLE  FOR  ANY  DIRECT,  INDIRECT,  INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR
Packit 534379
// CONSEQUENTIAL  DAMAGES  (INCLUDING,  BUT  NOT LIMITED  TO,  PROCUREMENT  OF
Packit 534379
// SUBSTITUTE GOODS OR SERVICES;  LOSS OF USE,  DATA, OR PROFITS;  OR BUSINESS
Packit 534379
// INTERRUPTION)  HOWEVER CAUSED  AND ON ANY THEORY  OF LIABILITY,  WHETHER IN
Packit 534379
// CONTRACT,  STRICT LIABILITY,  OR TORT  (INCLUDING NEGLIGENCE  OR OTHERWISE)
Packit 534379
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  EVEN IF ADVISED OF THE
Packit 534379
// POSSIBILITY OF SUCH DAMAGE.
Packit 534379
Packit 534379
#include <opae/fpga.h>
Packit 534379
#include <limits.h>
Packit 534379
Packit 534379
extern "C" {
Packit 534379
Packit 534379
typedef fpga_result (*filter_fn)(fpga_properties *, int, char **);
Packit 534379
typedef fpga_result (*command_fn)(fpga_token *, int, int, char **);
Packit 534379
typedef void (*help_fn)(void);
Packit 534379
Packit 534379
typedef enum metrics_inquiry { FPGA_ALL, FPGA_POWER, FPGA_THERMAL } metrics_inquiry;
Packit 534379
Packit 534379
struct command_handler {
Packit 534379
    const char *command;
Packit 534379
    filter_fn filter;
Packit 534379
    command_fn run;
Packit 534379
    help_fn help;
Packit 534379
};
Packit 534379
extern struct command_handler *cmd_array;
Packit 534379
Packit 534379
void help(void);
Packit 534379
Packit 534379
int parse_args(int argc, char *argv[]);
Packit 534379
Packit 534379
struct command_handler *get_command(char *cmd);
Packit 534379
Packit 534379
fpga_result errors_filter(fpga_properties *filter, int argc, char *argv[]);
Packit 534379
Packit 534379
fpga_result errors_command(fpga_token *tokens, int num_tokens, int argc,
Packit 534379
			   char *argv[]);
Packit 534379
void errors_help(void);
Packit 534379
Packit 534379
fpga_result fme_filter(fpga_properties *filter, int argc, char *argv[]);
Packit 534379
Packit 534379
fpga_result fme_command(fpga_token *tokens, int num_tokens, int argc,
Packit 534379
			char *argv[]);
Packit 534379
void fme_help(void);
Packit 534379
Packit 534379
void fpgainfo_print_common(const char *hdr, fpga_properties props);
Packit 534379
Packit 534379
void fpgainfo_print_err(const char *s, fpga_result res);
Packit 534379
Packit 534379
fpga_result port_filter(fpga_properties *filter, int argc, char *argv[]);
Packit 534379
Packit 534379
fpga_result port_command(fpga_token *tokens, int num_tokens, int argc,
Packit 534379
			 char *argv[]);
Packit 534379
void port_help(void);
Packit 534379
Packit 534379
fpga_result power_filter(fpga_properties *filter, int argc, char *argv[]);
Packit 534379
Packit 534379
fpga_result power_command(fpga_token *tokens, int num_tokens, int argc,
Packit 534379
			  char *argv[]);
Packit 534379
void power_help(void);
Packit 534379
Packit 534379
fpga_result temp_filter(fpga_properties *filter, int argc, char *argv[]);
Packit 534379
Packit 534379
fpga_result temp_command(fpga_token *tokens, int num_tokens, int argc,
Packit 534379
			 char *argv[]);
Packit 534379
void temp_help(void);
Packit 534379
Packit 534379
fpga_result bmc_filter(fpga_properties *filter, int argc, char *argv[]);
Packit 534379
Packit 534379
fpga_result bmc_command(fpga_token *tokens, int num_tokens, int argc,
Packit 534379
			 char *argv[]);
Packit 534379
void bmc_help(void);
Packit 534379
Packit 534379
fpga_result perf_command(fpga_token *tokens, int num_tokens, int argc,
Packit 534379
			 char *argv[]);
Packit 534379
void perf_help(void);
Packit 534379
Packit 534379
fpga_result get_metrics(fpga_token token, metrics_inquiry inquiry,
Packit 534379
                        fpga_metric_info *metrics_info, uint64_t *num_metrics_info,
Packit 534379
                        fpga_metric *metrics,uint64_t *num_metrics);
Packit 534379
Packit 534379
void replace_chars(char *str, char match, char rep);
Packit 534379
Packit 534379
void upcase_pci(char *str, size_t len);
Packit 534379
Packit 534379
void upcase_first(char *str);
Packit 534379
Packit 534379
int str_in_list(const char *key, const char *list[], size_t size);
Packit 534379
Packit 534379
int fpgainfo_main(int argc, char *argv[]);
Packit 534379
Packit 534379
int parse_error_args(int argc, char *argv[]);
Packit 534379
Packit 534379
}
Packit 534379
Packit 534379
#include <iostream>
Packit 534379
#include <vector>
Packit 534379
#include <cstdio>
Packit 534379
#include <cstdlib>
Packit 534379
#include <cstring>
Packit 534379
#include <errno.h>
Packit 534379
#include <unistd.h>
Packit 534379
#include "gtest/gtest.h"
Packit 534379
#include "mock/test_system.h"
Packit 534379
Packit 534379
using namespace opae::testing;
Packit 534379
Packit 534379
class fpgainfo_c_p : public ::testing::TestWithParam<std::string> {
Packit 534379
    protected:
Packit 534379
        fpgainfo_c_p() {}
Packit 534379
Packit 534379
        virtual void SetUp() override 
Packit 534379
        {
Packit 534379
            std::string platform_key = GetParam();
Packit 534379
            ASSERT_TRUE(test_platform::exists(platform_key));
Packit 534379
            platform_ = test_platform::get(platform_key);
Packit 534379
            system_ = test_system::instance();
Packit 534379
            system_->initialize();
Packit 534379
            system_->prepare_syfs(platform_);
Packit 534379
Packit 534379
            EXPECT_EQ(fpgaInitialize(nullptr), FPGA_OK);
Packit 534379
Packit 534379
            optind = 0;
Packit 534379
        }
Packit 534379
Packit 534379
        virtual void TearDown() override {
Packit 534379
            fpgaFinalize();
Packit 534379
            system_->finalize();
Packit 534379
        }
Packit 534379
Packit 534379
        test_platform platform_;
Packit 534379
        test_system *system_;
Packit 534379
};
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       get_command0
Packit 534379
 * @brief      Test: get_command
Packit 534379
 * @details    When passed with valid commands, the fn 
Packit 534379
 *             returns non-nullptr 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, get_command0) {
Packit 534379
    char cmd[20];
Packit 534379
Packit 534379
    strcpy(cmd, "errors");
Packit 534379
    EXPECT_NE(get_command(cmd), nullptr);
Packit 534379
Packit 534379
    strcpy(cmd, "power");
Packit 534379
    EXPECT_NE(get_command(cmd), nullptr);
Packit 534379
Packit 534379
    strcpy(cmd, "temp");
Packit 534379
    EXPECT_NE(get_command(cmd), nullptr);
Packit 534379
Packit 534379
    strcpy(cmd, "fme");
Packit 534379
    EXPECT_NE(get_command(cmd), nullptr);
Packit 534379
Packit 534379
    strcpy(cmd, "port");
Packit 534379
    EXPECT_NE(get_command(cmd), nullptr);
Packit 534379
Packit 534379
    /*
Packit 534379
    strcpy(cmd, "bmc");
Packit 534379
    EXPECT_NE(get_command(cmd), nullptr);
Packit 534379
    */
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       get_command1
Packit 534379
 * @brief      Test: get_command
Packit 534379
 * @details    When passed with invalid commands, the fn 
Packit 534379
 *             returns nullptr 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, get_command1) {
Packit 534379
    char cmd[20];
Packit 534379
Packit 534379
    strcpy(cmd, "???");
Packit 534379
    EXPECT_EQ(get_command(cmd), nullptr);
Packit 534379
}
Packit 534379
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       errors_filter0
Packit 534379
 * @brief      Test: errors_filter
Packit 534379
 * @details    When passed with valid arguments, the function 
Packit 534379
 *             returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, errors_filter0) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char two[20];
Packit 534379
    char three[20];
Packit 534379
    char *argv3[] = { zero, one, two };
Packit 534379
    char *argv4[] = { zero, one, two, three };
Packit 534379
Packit 534379
    fpga_properties filter = NULL;
Packit 534379
    ASSERT_EQ(fpgaGetProperties(NULL, &filter), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "errors");
Packit 534379
    strcpy(two, "fme");
Packit 534379
    EXPECT_EQ(errors_filter(&filter, 3, argv3), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(two, "port");
Packit 534379
    EXPECT_EQ(errors_filter(&filter, 3, argv3), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(two, "all");
Packit 534379
    EXPECT_EQ(errors_filter(&filter, 3, argv3), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(two, "fme");
Packit 534379
    strcpy(three, "-c");
Packit 534379
    EXPECT_EQ(errors_filter(&filter, 4, argv4), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(two, "port");
Packit 534379
    EXPECT_EQ(errors_filter(&filter, 4, argv4), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(two, "all");
Packit 534379
    EXPECT_EQ(errors_filter(&filter, 4, argv4), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(two, "fme");
Packit 534379
    strcpy(three, "--force");
Packit 534379
    EXPECT_EQ(errors_filter(&filter, 4, argv4), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(two, "port");
Packit 534379
    EXPECT_EQ(errors_filter(&filter, 4, argv4), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(two, "all");
Packit 534379
    EXPECT_EQ(errors_filter(&filter, 4, argv4), FPGA_OK);
Packit 534379
Packit 534379
    ASSERT_EQ(fpgaDestroyProperties(&filter), FPGA_OK);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       errors_command0
Packit 534379
 * @brief      Test: errors_command
Packit 534379
 * @details    When passed with valid arguments, the fn prints 
Packit 534379
 *             relevant information and returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, errors_command0) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char two[20];
Packit 534379
    char three[20];
Packit 534379
    char *argv3[] = { zero, one, two };
Packit 534379
    char *argv4[] = { zero, one, two, three };
Packit 534379
Packit 534379
    fpga_properties filter = NULL;
Packit 534379
    fpga_token *tokens = NULL;
Packit 534379
    uint32_t matches = 0, num_tokens = 0;;
Packit 534379
Packit 534379
    ASSERT_EQ(fpgaGetProperties(NULL, &filter), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaEnumerate(&filter, 1, NULL, 0, &matches), FPGA_OK);
Packit 534379
    ASSERT_GT(matches, 0);
Packit 534379
    tokens = (fpga_token *)malloc(matches * sizeof(fpga_token));
Packit 534379
Packit 534379
    num_tokens = matches;
Packit 534379
    ASSERT_EQ(fpgaEnumerate(&filter, 1, tokens, num_tokens, &matches), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "errors");
Packit 534379
    strcpy(two, "all");
Packit 534379
    EXPECT_EQ(errors_command(tokens, num_tokens, 3, argv3), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(two, "fme");
Packit 534379
    ASSERT_EQ(fpgaPropertiesSetObjectType(filter,FPGA_DEVICE), FPGA_OK);
Packit 534379
    EXPECT_EQ(errors_command(tokens, num_tokens, 3, argv3), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(two, "port");
Packit 534379
    ASSERT_EQ(fpgaPropertiesSetObjectType(filter,FPGA_ACCELERATOR), FPGA_OK);
Packit 534379
    EXPECT_EQ(errors_command(tokens, num_tokens, 3, argv3), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(two, "all");
Packit 534379
    strcpy(three, "-h");
Packit 534379
    EXPECT_EQ(errors_command(tokens, num_tokens, 4, argv4), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(two, "fme");
Packit 534379
    strcpy(three, "-h");
Packit 534379
    ASSERT_EQ(fpgaPropertiesSetObjectType(filter,FPGA_DEVICE), FPGA_OK);
Packit 534379
    EXPECT_EQ(errors_command(tokens, num_tokens, 4, argv4), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(two, "port");
Packit 534379
    strcpy(three, "-h");
Packit 534379
    ASSERT_EQ(fpgaPropertiesSetObjectType(filter,FPGA_ACCELERATOR), FPGA_OK);
Packit 534379
    EXPECT_EQ(errors_command(tokens, num_tokens, 4, argv4), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(two, "all");
Packit 534379
    strcpy(three, "-c");
Packit 534379
    EXPECT_EQ(errors_command(tokens, num_tokens, 4, argv4), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(two, "fme");
Packit 534379
    strcpy(three, "-c");
Packit 534379
    ASSERT_EQ(fpgaPropertiesSetObjectType(filter,FPGA_DEVICE), FPGA_OK);
Packit 534379
    EXPECT_EQ(errors_command(tokens, num_tokens, 4, argv4), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(two, "port");
Packit 534379
    strcpy(three, "-c");
Packit 534379
    ASSERT_EQ(fpgaPropertiesSetObjectType(filter,FPGA_ACCELERATOR), FPGA_OK);
Packit 534379
    EXPECT_EQ(errors_command(tokens, num_tokens, 4, argv4), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(two, "all");
Packit 534379
    strcpy(three, "--force");
Packit 534379
    EXPECT_EQ(errors_command(tokens, num_tokens, 4, argv4), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(two, "fme");
Packit 534379
    strcpy(three, "--force");
Packit 534379
    ASSERT_EQ(fpgaPropertiesSetObjectType(filter,FPGA_DEVICE), FPGA_OK);
Packit 534379
    EXPECT_EQ(errors_command(tokens, num_tokens, 4, argv4), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(two, "port");
Packit 534379
    strcpy(three, "--force");
Packit 534379
    ASSERT_EQ(fpgaPropertiesSetObjectType(filter,FPGA_ACCELERATOR), FPGA_OK);
Packit 534379
    EXPECT_EQ(errors_command(tokens, num_tokens, 4, argv4), FPGA_OK);
Packit 534379
Packit 534379
    for (uint32_t i = 0; i < num_tokens; ++i) {
Packit 534379
        fpgaDestroyToken(&tokens[i]);
Packit 534379
    }
Packit 534379
    free(tokens);
Packit 534379
    fpgaDestroyProperties(&filter);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       parse_error_args_errors_clear
Packit 534379
 * @brief      Test: parse_error_args
Packit 534379
 * @details    When passed the clear errors option, the function 
Packit 534379
 *             prints and clears errors.
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, parse_error_args_errors_clear) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char two[20];
Packit 534379
    char three[20];
Packit 534379
    char *argv[] = { zero, one, two, three };
Packit 534379
Packit 534379
    fpga_properties filter = NULL;
Packit 534379
    fpga_token *tokens = NULL;
Packit 534379
    uint32_t matches = 0, num_tokens = 0;;
Packit 534379
Packit 534379
    ASSERT_EQ(fpgaGetProperties(NULL, &filter), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaEnumerate(&filter, 1, NULL, 0, &matches), FPGA_OK);
Packit 534379
    ASSERT_GT(matches, 0);
Packit 534379
    tokens = (fpga_token *)malloc(matches * sizeof(fpga_token));
Packit 534379
Packit 534379
    num_tokens = matches;
Packit 534379
    ASSERT_EQ(fpgaEnumerate(&filter, 1, tokens, num_tokens, &matches), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "errors");
Packit 534379
    strcpy(two, "all");
Packit 534379
    strcpy(three, "-c");
Packit 534379
    EXPECT_EQ(parse_error_args(4, argv), 0);
Packit 534379
Packit 534379
    EXPECT_EQ(errors_command(tokens, num_tokens, 4, argv), FPGA_OK);
Packit 534379
Packit 534379
    for (uint32_t i = 0; i < num_tokens; ++i) {
Packit 534379
        fpgaDestroyToken(&tokens[i]);
Packit 534379
    }
Packit 534379
    free(tokens);
Packit 534379
    fpgaDestroyProperties(&filter);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       parse_error_args_neg
Packit 534379
 * @brief      Test: parse_error_args
Packit 534379
 * @details    When passed an invalid option, the function prints 
Packit 534379
 *             help message for errors subcommand and returns
Packit 534379
 *             an error.
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, parse_error_args_neg) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char *argv[] = { zero, one };
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "-k");
Packit 534379
    EXPECT_NE(parse_error_args(2, argv), 0);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       errors_help
Packit 534379
 * @brief      Test: errors_help
Packit 534379
 * @details    The function prints help message for errors 
Packit 534379
 *             subcommand.
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, errors_help) {
Packit 534379
    errors_help();
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       parse_error_args_help
Packit 534379
 * @brief      Test: parse_error_args
Packit 534379
 * @details    When passed the help option, the function prints 
Packit 534379
 *             help message for errors subcommand.
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, parse_error_args_help) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char *argv[] = { zero, one };
Packit 534379
Packit 534379
    std::string expected = "\nPrint and clear errors\n"
Packit 534379
                      "        fpgainfo errors [-h] [-c] {all,fme,port}\n\n"
Packit 534379
                      "                -h,--help           Print this help\n"
Packit 534379
                      "                -c,--clear          Clear all errors\n"
Packit 534379
                      "                --force             Retry clearing errors 64 times\n"
Packit 534379
                      "                                    to clear certain error conditions\n"
Packit 534379
                      "\n";
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "-h");
Packit 534379
Packit 534379
    testing::internal::CaptureStdout();
Packit 534379
Packit 534379
    EXPECT_NE(parse_error_args(2, argv), 0);
Packit 534379
Packit 534379
    std::string log_stdout = testing::internal::GetCapturedStdout();
Packit 534379
Packit 534379
    EXPECT_TRUE(log_stdout.find(expected) != std::string::npos);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       errors_filter1
Packit 534379
 * @brief      Test: errors_filter
Packit 534379
 * @details    When passed with invalid arguments, the function 
Packit 534379
 *             prints help message and returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, errors_filter1) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char two[20];
Packit 534379
    char *argv[] = { zero, one, two };
Packit 534379
Packit 534379
    fpga_properties filter = NULL;
Packit 534379
    ASSERT_EQ(fpgaGetProperties(NULL, &filter), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "errors");
Packit 534379
    strcpy(two, "???");
Packit 534379
    EXPECT_EQ(errors_filter(&filter, 3, argv), FPGA_OK);
Packit 534379
Packit 534379
    ASSERT_EQ(fpgaDestroyProperties(&filter), FPGA_OK);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       errors_filter2
Packit 534379
 * @brief      Test: errors_filter
Packit 534379
 * @details    When passed with argument that requires additional 
Packit 534379
 *             option, missing the option causes the fn to print 
Packit 534379
 *             help messages and return FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, errors_filter2) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char two[20];
Packit 534379
    char *argv2[] = { zero, one };
Packit 534379
    char *argv3[] = { zero, one, two };
Packit 534379
Packit 534379
    fpga_properties filter = NULL;
Packit 534379
    ASSERT_EQ(fpgaGetProperties(NULL, &filter), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "errors");
Packit 534379
    EXPECT_EQ(errors_filter(&filter, 2, argv2), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(two, "-c");
Packit 534379
    EXPECT_EQ(errors_filter(&filter, 3, argv3), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(two, "--force");
Packit 534379
    EXPECT_EQ(errors_filter(&filter, 3, argv3), FPGA_OK);
Packit 534379
Packit 534379
    ASSERT_EQ(fpgaDestroyProperties(&filter), FPGA_OK);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       fme_filter0
Packit 534379
 * @brief      Test: fme_filter
Packit 534379
 * @details    When passed with valid arguments, the function 
Packit 534379
 *             returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, fme_filter0) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char *argv[] = { zero, one };
Packit 534379
Packit 534379
    fpga_properties filter = NULL;
Packit 534379
    ASSERT_EQ(fpgaGetProperties(NULL, &filter), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "fme");
Packit 534379
    EXPECT_EQ(fme_filter(&filter, 2, argv), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaDestroyProperties(&filter), FPGA_OK);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       fme_command0
Packit 534379
 * @brief      Test: fme_command
Packit 534379
 * @details    When passed with valid arguments, the fn prints 
Packit 534379
 *             relevant information and returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, fme_command0) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char *argv[] = { zero, one };
Packit 534379
Packit 534379
    fpga_properties filter = NULL;
Packit 534379
    fpga_token *tokens = NULL;
Packit 534379
    uint32_t matches = 0, num_tokens = 0;;
Packit 534379
Packit 534379
    ASSERT_EQ(fpgaGetProperties(NULL, &filter), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaPropertiesSetObjectType(filter,FPGA_DEVICE), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaEnumerate(&filter, 1, NULL, 0, &matches), FPGA_OK);
Packit 534379
    ASSERT_GT(matches, 0);
Packit 534379
    tokens = (fpga_token *)malloc(matches * sizeof(fpga_token));
Packit 534379
Packit 534379
    num_tokens = matches;
Packit 534379
    ASSERT_EQ(fpgaEnumerate(&filter, 1, tokens, num_tokens, &matches), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "fme");
Packit 534379
    EXPECT_EQ(fme_command(tokens, num_tokens, 2, argv), FPGA_OK);
Packit 534379
Packit 534379
    for (uint32_t i = 0; i < num_tokens; ++i) {
Packit 534379
        fpgaDestroyToken(&tokens[i]);
Packit 534379
    }
Packit 534379
    free(tokens);
Packit 534379
    fpgaDestroyProperties(&filter);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       fme_command1
Packit 534379
 * @brief      Test: fme_command
Packit 534379
 * @details    When passed with '-h', the fn prints 
Packit 534379
 *             fme help message and returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, fme_command1) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char two[20];
Packit 534379
    char *argv[] = { zero, one, two };
Packit 534379
Packit 534379
    fpga_token *tokens = NULL;
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "fme");
Packit 534379
    strcpy(two, "-h");
Packit 534379
    EXPECT_EQ(fme_command(tokens, 0, 3, argv), FPGA_OK);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       fme_help
Packit 534379
 * @brief      Test: fme_help
Packit 534379
 * @details    The function prints help message for fme subcommand.
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, fme_help) {
Packit 534379
    fme_help();
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       port_filter0
Packit 534379
 * @brief      Test: port_filter
Packit 534379
 * @details    When passed with valid arguments, the function 
Packit 534379
 *             returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, port_filter0) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char *argv[] = { zero, one };
Packit 534379
Packit 534379
    fpga_properties filter = NULL;
Packit 534379
    ASSERT_EQ(fpgaGetProperties(NULL, &filter), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "port");
Packit 534379
    EXPECT_EQ(port_filter(&filter, 2, argv), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaDestroyProperties(&filter), FPGA_OK);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       port_command0
Packit 534379
 * @brief      Test: port_command
Packit 534379
 * @details    When passed with valid arguments, the fn prints 
Packit 534379
 *             relevant information and returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, port_command0) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char *argv[] = { zero, one };
Packit 534379
Packit 534379
    fpga_properties filter = NULL;
Packit 534379
    fpga_token *tokens = NULL;
Packit 534379
    uint32_t matches = 0, num_tokens = 0;;
Packit 534379
Packit 534379
    ASSERT_EQ(fpgaGetProperties(NULL, &filter), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaPropertiesSetObjectType(filter,FPGA_ACCELERATOR), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaEnumerate(&filter, 1, NULL, 0, &matches), FPGA_OK);
Packit 534379
    ASSERT_GT(matches, 0);
Packit 534379
    tokens = (fpga_token *)malloc(matches * sizeof(fpga_token));
Packit 534379
Packit 534379
    num_tokens = matches;
Packit 534379
    ASSERT_EQ(fpgaEnumerate(&filter, 1, tokens, num_tokens, &matches), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "port");
Packit 534379
    EXPECT_EQ(port_command(tokens, num_tokens, 2, argv), FPGA_OK);
Packit 534379
Packit 534379
    for (uint32_t i = 0; i < num_tokens; ++i) {
Packit 534379
        fpgaDestroyToken(&tokens[i]);
Packit 534379
    }
Packit 534379
    free(tokens);
Packit 534379
    fpgaDestroyProperties(&filter);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       port_command1
Packit 534379
 * @brief      Test: port_command
Packit 534379
 * @details    When passed with '-h', the fn prints 
Packit 534379
 *             port help message and returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, port_command1) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char two[20];
Packit 534379
    char *argv[] = { zero, one, two };
Packit 534379
Packit 534379
    fpga_token *tokens = NULL;
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "port");
Packit 534379
    strcpy(two, "-h");
Packit 534379
    EXPECT_EQ(port_command(tokens, 0, 3, argv), FPGA_OK);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       port_help
Packit 534379
 * @brief      Test: port_help
Packit 534379
 * @details    The function prints help message for port subcommand.
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, port_help) {
Packit 534379
    port_help();
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       power_filter0
Packit 534379
 * @brief      Test: power_filter
Packit 534379
 * @details    When passed with valid arguments, the function 
Packit 534379
 *             returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, power_filter0) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char *argv[] = { zero, one };
Packit 534379
Packit 534379
    fpga_properties filter = NULL;
Packit 534379
    ASSERT_EQ(fpgaGetProperties(NULL, &filter), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "power");
Packit 534379
    EXPECT_EQ(power_filter(&filter, 2, argv), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaDestroyProperties(&filter), FPGA_OK);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       power_command0
Packit 534379
 * @brief      Test: power_command
Packit 534379
 * @details    When passed with valid arguments, the fn prints 
Packit 534379
 *             relevant information and returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, power_command0) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char *argv[] = { zero, one };
Packit 534379
Packit 534379
    fpga_properties filter = NULL;
Packit 534379
    fpga_token *tokens = NULL;
Packit 534379
    uint32_t matches = 0, num_tokens = 0;;
Packit 534379
Packit 534379
    ASSERT_EQ(fpgaGetProperties(NULL, &filter), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaPropertiesSetObjectType(filter,FPGA_DEVICE), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaEnumerate(&filter, 1, NULL, 0, &matches), FPGA_OK);
Packit 534379
    ASSERT_GT(matches, 0);
Packit 534379
    tokens = (fpga_token *)malloc(matches * sizeof(fpga_token));
Packit 534379
Packit 534379
    num_tokens = matches;
Packit 534379
    ASSERT_EQ(fpgaEnumerate(&filter, 1, tokens, num_tokens, &matches), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "power");
Packit 534379
    EXPECT_EQ(power_command(tokens, num_tokens, 2, argv), FPGA_OK);
Packit 534379
Packit 534379
    for (uint32_t i = 0; i < num_tokens; ++i) {
Packit 534379
        fpgaDestroyToken(&tokens[i]);
Packit 534379
    }
Packit 534379
    free(tokens);
Packit 534379
    fpgaDestroyProperties(&filter);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       power_command1
Packit 534379
 * @brief      Test: power_command
Packit 534379
 * @details    When passed with '-h', the fn prints 
Packit 534379
 *             power help message and returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, power_command1) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char two[20];
Packit 534379
    char *argv[] = { zero, one, two };
Packit 534379
Packit 534379
    fpga_token *tokens = NULL;
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "power");
Packit 534379
    strcpy(two, "-h");
Packit 534379
    EXPECT_EQ(power_command(tokens, 0, 3, argv), FPGA_OK);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       power_help
Packit 534379
 * @brief      Test: power_help
Packit 534379
 * @details    The function prints help message for power subcommand.
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, power_help) {
Packit 534379
    power_help();
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       temp_filter0
Packit 534379
 * @brief      Test: temp_filter
Packit 534379
 * @details    When passed with valid arguments, the function 
Packit 534379
 *             returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, temp_filter0) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char *argv[] = { zero, one };
Packit 534379
Packit 534379
    fpga_properties filter = NULL;
Packit 534379
    ASSERT_EQ(fpgaGetProperties(NULL, &filter), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "temp");
Packit 534379
    EXPECT_EQ(temp_filter(&filter, 2, argv), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaDestroyProperties(&filter), FPGA_OK);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       temp_command0
Packit 534379
 * @brief      Test: temp_command
Packit 534379
 * @details    When passed with valid arguments, the fn prints 
Packit 534379
 *             relevant information and returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, temp_command0) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char *argv[] = { zero, one };
Packit 534379
Packit 534379
    fpga_properties filter = NULL;
Packit 534379
    fpga_token *tokens = NULL;
Packit 534379
    uint32_t matches = 0, num_tokens = 0;;
Packit 534379
Packit 534379
    ASSERT_EQ(fpgaGetProperties(NULL, &filter), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaPropertiesSetObjectType(filter,FPGA_DEVICE), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaEnumerate(&filter, 1, NULL, 0, &matches), FPGA_OK);
Packit 534379
    ASSERT_GT(matches, 0);
Packit 534379
    tokens = (fpga_token *)malloc(matches * sizeof(fpga_token));
Packit 534379
Packit 534379
    num_tokens = matches;
Packit 534379
    ASSERT_EQ(fpgaEnumerate(&filter, 1, tokens, num_tokens, &matches), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "temp");
Packit 534379
    EXPECT_EQ(temp_command(tokens, num_tokens, 2, argv), FPGA_OK);
Packit 534379
Packit 534379
    for (uint32_t i = 0; i < num_tokens; ++i) {
Packit 534379
        fpgaDestroyToken(&tokens[i]);
Packit 534379
    }
Packit 534379
    free(tokens);
Packit 534379
    fpgaDestroyProperties(&filter);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       temp_command1
Packit 534379
 * @brief      Test: temp_command
Packit 534379
 * @details    When passed with '-h', the fn prints 
Packit 534379
 *             temp help message and returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, temp_command1) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char two[20];
Packit 534379
    char *argv[] = { zero, one, two };
Packit 534379
Packit 534379
    fpga_token *tokens = NULL;
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "temp");
Packit 534379
    strcpy(two, "-h");
Packit 534379
    EXPECT_EQ(temp_command(tokens, 0, 3, argv), FPGA_OK);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       temp_help
Packit 534379
 * @brief      Test: temp_help
Packit 534379
 * @details    The function prints help message for temp subcommand.
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, temp_help) {
Packit 534379
    temp_help();
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       bmc_filter0
Packit 534379
 * @brief      Test: bmc_filter
Packit 534379
 * @details    When passed with valid arguments, the function 
Packit 534379
 *             returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, bmc_filter0) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char *argv[] = { zero, one };
Packit 534379
Packit 534379
    fpga_properties filter = NULL;
Packit 534379
    ASSERT_EQ(fpgaGetProperties(NULL, &filter), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "bmc");
Packit 534379
    EXPECT_EQ(bmc_filter(&filter, 2, argv), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaDestroyProperties(&filter), FPGA_OK);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       bmc_command0
Packit 534379
 * @brief      Test: bmc_command
Packit 534379
 * @details    When passed with valid arguments, the fn prints 
Packit 534379
 *             relevant information and returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, bmc_command0) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char *argv[] = { zero, one };
Packit 534379
Packit 534379
    fpga_properties filter = NULL;
Packit 534379
    fpga_token *tokens = NULL;
Packit 534379
    uint32_t matches = 0, num_tokens = 0;;
Packit 534379
Packit 534379
    ASSERT_EQ(fpgaGetProperties(NULL, &filter), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaPropertiesSetObjectType(filter,FPGA_DEVICE), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaEnumerate(&filter, 1, NULL, 0, &matches), FPGA_OK);
Packit 534379
    ASSERT_GT(matches, 0);
Packit 534379
    tokens = (fpga_token *)malloc(matches * sizeof(fpga_token));
Packit 534379
Packit 534379
    num_tokens = matches;
Packit 534379
    ASSERT_EQ(fpgaEnumerate(&filter, 1, tokens, num_tokens, &matches), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "bmc");
Packit 534379
    EXPECT_EQ(bmc_command(tokens, num_tokens, 2, argv), FPGA_OK);
Packit 534379
Packit 534379
    for (uint32_t i = 0; i < num_tokens; ++i) {
Packit 534379
        fpgaDestroyToken(&tokens[i]);
Packit 534379
    }
Packit 534379
    free(tokens);
Packit 534379
    fpgaDestroyProperties(&filter);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       bmc_command1
Packit 534379
 * @brief      Test: bmc_command
Packit 534379
 * @details    When passed with '-h', the fn prints 
Packit 534379
 *             bmc help message and returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, bmc_command1) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char two[20];
Packit 534379
    char *argv[] = { zero, one, two };
Packit 534379
Packit 534379
    fpga_token *tokens = NULL;
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "bmc");
Packit 534379
    strcpy(two, "-h");
Packit 534379
    EXPECT_EQ(bmc_command(tokens, 0, 3, argv), FPGA_OK);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       bmc_command2
Packit 534379
 * @brief      Test: bmc_command
Packit 534379
 * @details    When passed with invalid '-xyz', the fn prints 
Packit 534379
 *             bmc help message and returns FPGA_INVALID_PARAM. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, bmc_command2) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char two[20];
Packit 534379
    char *argv[] = { zero, one, two };
Packit 534379
Packit 534379
    fpga_token *tokens = NULL;
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "bmc");
Packit 534379
    strcpy(two, "-xyz");
Packit 534379
    EXPECT_EQ(bmc_command(tokens, 0, 3, argv), FPGA_INVALID_PARAM);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       perf_command0
Packit 534379
 * @brief      Test: perf_command
Packit 534379
 * @details    When passed with valid arguments, the fn prints 
Packit 534379
 *             relevant information and returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, perf_command0) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char *argv[] = { zero, one };
Packit 534379
Packit 534379
    fpga_properties filter = NULL;
Packit 534379
    fpga_token *tokens = NULL;
Packit 534379
    uint32_t matches = 0, num_tokens = 0;;
Packit 534379
Packit 534379
    ASSERT_EQ(fpgaGetProperties(NULL, &filter), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaPropertiesSetObjectType(filter,FPGA_DEVICE), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaEnumerate(&filter, 1, NULL, 0, &matches), FPGA_OK);
Packit 534379
    ASSERT_GT(matches, 0);
Packit 534379
    tokens = (fpga_token *)malloc(matches * sizeof(fpga_token));
Packit 534379
Packit 534379
    num_tokens = matches;
Packit 534379
    ASSERT_EQ(fpgaEnumerate(&filter, 1, tokens, num_tokens, &matches), FPGA_OK);
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "perf");
Packit 534379
    EXPECT_EQ(perf_command(tokens, num_tokens, 2, argv), FPGA_OK);
Packit 534379
Packit 534379
    for (uint32_t i = 0; i < num_tokens; ++i) {
Packit 534379
        fpgaDestroyToken(&tokens[i]);
Packit 534379
    }
Packit 534379
    free(tokens);
Packit 534379
    fpgaDestroyProperties(&filter);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       perf_command1
Packit 534379
 * @brief      Test: perf_command
Packit 534379
 * @details    When passed with '-h', the fn prints 
Packit 534379
 *             perf help message and returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, perf_command1) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char two[20];
Packit 534379
    char *argv[] = { zero, one, two };
Packit 534379
Packit 534379
    fpga_token *tokens = NULL;
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "perf");
Packit 534379
    strcpy(two, "-h");
Packit 534379
    EXPECT_EQ(perf_command(tokens, 0, 3, argv), FPGA_OK);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       perf_command2
Packit 534379
 * @brief      Test: perf_command
Packit 534379
 * @details    When passed with invalid '-xyz' param, the fn prints 
Packit 534379
 *             perf help message and returns FPGA_INVALID_PARAM. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, perf_command2) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char two[20];
Packit 534379
    char *argv[] = { zero, one, two };
Packit 534379
Packit 534379
    fpga_token *tokens = NULL;
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "perf");
Packit 534379
    strcpy(two, "-xyz");
Packit 534379
    EXPECT_EQ(perf_command(tokens, 0, 3, argv), FPGA_INVALID_PARAM);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       bmc_help
Packit 534379
 * @brief      Test: bmc_help
Packit 534379
 * @details    The function prints help message for bmc subcommand.
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, bmc_help) {
Packit 534379
    bmc_help();
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       perf_help
Packit 534379
 * @brief      Test: perf_help
Packit 534379
 * @details    The function prints help message for perf subcommand.
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, perf_help) {
Packit 534379
    perf_help();
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       get_metrics0
Packit 534379
 * @brief      Test: get_metrics
Packit 534379
 * @details    When passed with valid arguments, the fn 
Packit 534379
 *             retrieve required information from BMC and 
Packit 534379
 *             returns FPGA_OK. 
Packit 534379
 */
Packit 534379
Packit 534379
TEST_P(fpgainfo_c_p, get_metrics0) {
Packit 534379
    fpga_properties filter = NULL;
Packit 534379
    fpga_token token;
Packit 534379
    fpga_metric_info metrics_info[64];
Packit 534379
    fpga_metric metrics[64];
Packit 534379
    uint64_t num_metrics;
Packit 534379
    uint64_t num_metrics_info;
Packit 534379
    uint32_t matches = 0;
Packit 534379
Packit 534379
    ASSERT_EQ(fpgaGetProperties(NULL, &filter), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaPropertiesSetObjectType(filter,FPGA_DEVICE), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaEnumerate(&filter, 1, &token, 1, &matches), FPGA_OK);
Packit 534379
Packit 534379
    EXPECT_EQ(get_metrics(token, FPGA_ALL, metrics_info, &num_metrics_info, metrics, &num_metrics), FPGA_OK);
Packit 534379
Packit 534379
    fpgaDestroyToken(&token);
Packit 534379
    fpgaDestroyProperties(&filter);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       get_metrics1
Packit 534379
 * @brief      Test: get_metrics
Packit 534379
 * @details    When passed with valid arguments, the fn 
Packit 534379
 *             retrieve required information from BMC and 
Packit 534379
 *             returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, get_metrics1) {
Packit 534379
    fpga_properties filter = NULL;
Packit 534379
    fpga_token token;
Packit 534379
    fpga_metric_info metrics_info[64];
Packit 534379
    fpga_metric metrics[64];
Packit 534379
    uint64_t num_metrics;
Packit 534379
    uint64_t num_metrics_info;
Packit 534379
    uint32_t matches = 0;
Packit 534379
Packit 534379
    ASSERT_EQ(fpgaGetProperties(NULL, &filter), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaPropertiesSetObjectType(filter,FPGA_DEVICE), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaEnumerate(&filter, 1, &token, 1, &matches), FPGA_OK);
Packit 534379
Packit 534379
    EXPECT_EQ(get_metrics(token, FPGA_POWER, metrics_info, &num_metrics_info, metrics, &num_metrics), FPGA_OK);
Packit 534379
Packit 534379
    fpgaDestroyToken(&token);
Packit 534379
    fpgaDestroyProperties(&filter);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       get_metrics2
Packit 534379
 * @brief      Test: get_metrics
Packit 534379
 * @details    When passed with valid arguments, the fn 
Packit 534379
 *             retrieve required information from BMC and 
Packit 534379
 *             returns FPGA_OK. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, get_metrics2) {
Packit 534379
    fpga_properties filter = NULL;
Packit 534379
    fpga_token token;
Packit 534379
    fpga_metric_info metrics_info[64];
Packit 534379
    fpga_metric metrics[64];
Packit 534379
    uint64_t num_metrics;
Packit 534379
    uint64_t num_metrics_info;
Packit 534379
    uint32_t matches = 0;
Packit 534379
Packit 534379
    ASSERT_EQ(fpgaGetProperties(NULL, &filter), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaPropertiesSetObjectType(filter,FPGA_DEVICE), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaEnumerate(&filter, 1, &token, 1, &matches), FPGA_OK);
Packit 534379
Packit 534379
    EXPECT_EQ(get_metrics(token, FPGA_THERMAL, metrics_info, &num_metrics_info, metrics, &num_metrics), FPGA_OK);
Packit 534379
Packit 534379
    fpgaDestroyToken(&token);
Packit 534379
    fpgaDestroyProperties(&filter);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       fpgainfo_print_common
Packit 534379
 * @brief      Test: fpgainfo_print_common
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, fpgainfo_print_common) {
Packit 534379
    fpga_properties filter = NULL;
Packit 534379
    fpga_token token = nullptr;
Packit 534379
    uint32_t matches = 0;;
Packit 534379
Packit 534379
    ASSERT_EQ(fpgaGetProperties(NULL, &filter), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaPropertiesSetObjectType(filter,FPGA_DEVICE), FPGA_OK);
Packit 534379
    ASSERT_EQ(fpgaEnumerate(&filter, 1, &token, 1, &matches), FPGA_OK);
Packit 534379
Packit 534379
    fpgainfo_print_common("//****** HEADER ******//", filter);
Packit 534379
Packit 534379
    fpgaDestroyToken(&token);
Packit 534379
    fpgaDestroyProperties(&filter);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       fpgainfo_print_err
Packit 534379
 * @brief      Test: fpgainfo_print_err
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, fpgainfo_print_err) {
Packit 534379
    fpgainfo_print_err("ERROR:", FPGA_INVALID_PARAM);
Packit 534379
    fpgainfo_print_err("ERROR:", FPGA_BUSY);
Packit 534379
    fpgainfo_print_err("ERROR:", FPGA_EXCEPTION);
Packit 534379
    fpgainfo_print_err("ERROR:", FPGA_NOT_FOUND);
Packit 534379
    fpgainfo_print_err("ERROR:", FPGA_NO_MEMORY);
Packit 534379
    fpgainfo_print_err("ERROR:", FPGA_NOT_SUPPORTED);
Packit 534379
    fpgainfo_print_err("ERROR:", FPGA_NO_DRIVER);
Packit 534379
    fpgainfo_print_err("ERROR:", FPGA_NO_DAEMON);
Packit 534379
    fpgainfo_print_err("ERROR:", FPGA_NO_ACCESS);
Packit 534379
    fpgainfo_print_err("ERROR:", FPGA_NO_ACCESS);
Packit 534379
}
Packit 534379
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       replace_chars0
Packit 534379
 * @brief      Test: replace_chars
Packit 534379
 */
Packit 534379
TEST(fpgainfo_c, replace_chars0) {
Packit 534379
    char input[256];
Packit 534379
    strcpy(input, "one_two_three_four");
Packit 534379
    replace_chars(input, '_', ' ');
Packit 534379
    EXPECT_STREQ(input, "one two three four");
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       replace_chars1
Packit 534379
 * @brief      Test: replace_chars
Packit 534379
 */
Packit 534379
TEST(fpgainfo_c, replace_chars1) {
Packit 534379
    char input[256];
Packit 534379
    strcpy(input, "one_two_three_four");
Packit 534379
    replace_chars(input, ':', ' ');
Packit 534379
    EXPECT_STREQ(input, "one_two_three_four");
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       upcase_pci0
Packit 534379
 * @brief      Test: upcase_pci
Packit 534379
 */
Packit 534379
TEST(fpgainfo_c, upcase_pci0) {
Packit 534379
    char input[256];
Packit 534379
    strcpy(input, "pcie 0");
Packit 534379
    upcase_pci(input, strnlen(input, 256));
Packit 534379
    EXPECT_STREQ(input, "PCIe 0");
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       upcase_pci1
Packit 534379
 * @brief      Test: upcase_pci
Packit 534379
 */
Packit 534379
TEST(fpgainfo_c, upcase_pci1) {
Packit 534379
    char input[256];
Packit 534379
    strcpy(input, "  pcie 0 pcie 1 pcie 2  ");
Packit 534379
    upcase_pci(input, strnlen(input, 256));
Packit 534379
    EXPECT_STREQ(input, "  PCIe 0 PCIe 1 PCIe 2  ");
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       upcase_pci2
Packit 534379
 * @brief      Test: upcase_pci
Packit 534379
 */
Packit 534379
TEST(fpgainfo_c, upcase_pci2) {
Packit 534379
    char input[256];
Packit 534379
    strcpy(input, " pc ");
Packit 534379
    upcase_pci(input, strnlen(input, 256));
Packit 534379
    EXPECT_STREQ(input, " pc ");
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       upcase_first0
Packit 534379
 * @brief      Test: upcase_first
Packit 534379
 */
Packit 534379
TEST(fpgainfo_c, upcase_first0) {
Packit 534379
    char input[256];
Packit 534379
    strcpy(input, "one two three four");
Packit 534379
    upcase_first(input);
Packit 534379
    EXPECT_STREQ(input, "One Two Three Four");
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       upcase_first1
Packit 534379
 * @brief      Test: upcase_first
Packit 534379
 */
Packit 534379
TEST(fpgainfo_c, upcase_first1) {
Packit 534379
    char input[256];
Packit 534379
    strcpy(input, "One Two Three Four");
Packit 534379
    upcase_first(input);
Packit 534379
    EXPECT_STREQ(input, "One Two Three Four");
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       upcase_first2
Packit 534379
 * @brief      Test: upcase_first
Packit 534379
 */
Packit 534379
TEST(fpgainfo_c, upcase_first2) {
Packit 534379
    char input[256] = { 0 };
Packit 534379
    strcpy(input, "");
Packit 534379
    upcase_first(input);
Packit 534379
    EXPECT_STREQ(input, "");
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       str_in_list0
Packit 534379
 * @brief      Test: upcase_first
Packit 534379
 */
Packit 534379
TEST(fpgainfo_c, str_in_list0) {
Packit 534379
    const char *slist[] = { "one", "two", "two", "three", "four" };
Packit 534379
    int idx = str_in_list("one", slist, 5);
Packit 534379
    EXPECT_EQ(idx, 0);
Packit 534379
Packit 534379
    idx = str_in_list("two", slist, 5);
Packit 534379
    EXPECT_EQ(idx, 1);
Packit 534379
Packit 534379
    idx = str_in_list("three", slist, 5);
Packit 534379
    EXPECT_EQ(idx, 3);
Packit 534379
Packit 534379
    idx = str_in_list("four", slist, 5);
Packit 534379
    EXPECT_EQ(idx, 4);
Packit 534379
Packit 534379
    idx = str_in_list("five", slist, 5);
Packit 534379
    EXPECT_EQ(idx, INT_MAX);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       parse_args0
Packit 534379
 * @brief      Test: parse_args
Packit 534379
 * @details    When passed with valid command options, 
Packit 534379
 *             the fn returns 0. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, parse_args0) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char *argv[] = { zero, one };
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "fme");
Packit 534379
    EXPECT_EQ(parse_args(2, argv), 0);
Packit 534379
Packit 534379
    strcpy(one, "port");
Packit 534379
    EXPECT_EQ(parse_args(2, argv), 0);
Packit 534379
Packit 534379
    strcpy(one, "power");
Packit 534379
    EXPECT_EQ(parse_args(2, argv), 0);
Packit 534379
Packit 534379
    strcpy(one, "temp");
Packit 534379
    EXPECT_EQ(parse_args(2, argv), 0);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       parse_args1
Packit 534379
 * @brief      Test: parse_args
Packit 534379
 * @details    When passed with '-h' or '--help', the fn 
Packit 534379
 *             prints help message and return non-zero. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, parse_args1) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char *argv[] = { zero, one };
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "-h");
Packit 534379
    EXPECT_NE(parse_args(2, argv), 0);
Packit 534379
Packit 534379
    optind = 0;
Packit 534379
    strcpy(one, "--help");
Packit 534379
    EXPECT_NE(parse_args(2, argv), 0);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       parse_args2
Packit 534379
 * @brief      Test: parse_args
Packit 534379
 * @details    When passed with invalid options, the fn 
Packit 534379
 *             prints error message and return zero. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, parse_args2) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char *argv[] = { zero, one };
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "?");
Packit 534379
    EXPECT_EQ(parse_args(2, argv), 0);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       parse_args3
Packit 534379
 * @brief      Test: parse_args
Packit 534379
 * @details    When passed with an invalid options, the fn 
Packit 534379
 *             returns zero. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, parse_args3) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char *argv[] = { zero, one };
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "κόσμε");
Packit 534379
Packit 534379
    /* FIXME: Parse_arg will return 0 on all inputs
Packit 534379
              that doesn't match MAIN_GETOPT_STRING.
Packit 534379
              Main fails on get_command call but
Packit 534379
              will return 0.
Packit 534379
Packit 534379
    */
Packit 534379
    EXPECT_EQ(parse_args(2, argv), 0);
Packit 534379
    EXPECT_EQ(fpgainfo_main(2, argv), 0);
Packit 534379
Packit 534379
    strcpy(one, "\x00 \x09\x0A\x0D\x20\x7E");
Packit 534379
Packit 534379
    EXPECT_EQ(parse_args(2, argv), 0);
Packit 534379
    EXPECT_EQ(fpgainfo_main(2, argv), 0);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       help
Packit 534379
 * @brief      Test: help
Packit 534379
 * @details    help displays the application help message.
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, help) {
Packit 534379
    help();
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       main_1
Packit 534379
 * @brief      Test: fpgainfo_main
Packit 534379
 * @details    When passed with no argument, the fn 
Packit 534379
 *             returns an error. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, main_1) {
Packit 534379
    char zero[20];
Packit 534379
    char *argv[] = { zero };
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
Packit 534379
    EXPECT_NE(fpgainfo_main(1, argv), 0);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       main_2
Packit 534379
 * @brief      Test: fpgainfo_main
Packit 534379
 * @details    When passed with the version option, the fn 
Packit 534379
 *             returns zero. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, main_2) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char *argv[] = { zero, one };
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "-v");
Packit 534379
Packit 534379
    EXPECT_EQ(fpgainfo_main(2, argv), 0);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       main_3
Packit 534379
 * @brief      Test: fpgainfo_main
Packit 534379
 * @details    When missing an argument, the fn 
Packit 534379
 *             returns an error. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, main_3) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char *argv[] = { zero, one };
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "-B");
Packit 534379
Packit 534379
    EXPECT_NE(fpgainfo_main(2, argv), 0);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       main_4
Packit 534379
 * @brief      Test: fpgainfo_main
Packit 534379
 * @details    When passed with invalid option, the fn 
Packit 534379
 *             returns an error. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, main_4) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char *argv[] = { zero, one };
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "-K");
Packit 534379
Packit 534379
    EXPECT_NE(fpgainfo_main(2, argv), 0);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       main_5
Packit 534379
 * @brief      Test: fpgainfo_main
Packit 534379
 * @details    When passed with valid option, the fn 
Packit 534379
 *             returns 0. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, main_5) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char two[20];
Packit 534379
    char three[20];
Packit 534379
    char *argv[] = { zero, one, two, three };
Packit 534379
    char bus[10];
Packit 534379
Packit 534379
    sprintf(bus, "0x%x", platform_.devices[0].bus);
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "fme");
Packit 534379
    strcpy(two, "-B");
Packit 534379
    strcpy(three, bus);
Packit 534379
Packit 534379
    EXPECT_EQ(fpgainfo_main(4, argv), 0);
Packit 534379
}
Packit 534379
Packit 534379
/**
Packit 534379
 * @test       main_6
Packit 534379
 * @brief      Test: fpgainfo_main
Packit 534379
 * @details    When passed with invalid option, the fn 
Packit 534379
 *             returns an error. 
Packit 534379
 */
Packit 534379
TEST_P(fpgainfo_c_p, main_6) {
Packit 534379
    char zero[20];
Packit 534379
    char one[20];
Packit 534379
    char two[20];
Packit 534379
    char three[20];
Packit 534379
    char *argv[] = { zero, one, two, three };
Packit 534379
Packit 534379
    strcpy(zero, "fpgainfo");
Packit 534379
    strcpy(one, "fme");
Packit 534379
    strcpy(two, "-B");
Packit 534379
    strcpy(three, "0xFF");
Packit 534379
Packit 534379
    EXPECT_NE(fpgainfo_main(4, argv), 0);
Packit 534379
}
Packit 534379
Packit 534379
INSTANTIATE_TEST_CASE_P(fpgainfo_c, fpgainfo_c_p,
Packit 534379
        ::testing::ValuesIn(test_platform::platforms({ "skx-p","dcp-rc","dcp-vc" })));