Skip to content

Commit

Permalink
adaptived: tests: cleanup test warnings to avoid rpmbuild warnings
Browse files Browse the repository at this point in the history
Cleanup warnings in tests/ftests and  tests/gunit to avoid
rpmbuild warnings.

Signed-off-by: George Kennedy <george.kennedy@oracle.com>
Reviewed-by: Tom Hromatka <tom.hromatka@oracle.com>
Acked-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
  • Loading branch information
gkennedy12 authored and drakenclimber committed Jan 6, 2025
1 parent 5cc9c5f commit 89b8751
Show file tree
Hide file tree
Showing 28 changed files with 75 additions and 100 deletions.
1 change: 0 additions & 1 deletion adaptived/tests/ftests/010-snooze_effect.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ int main(int argc, char *argv[])
struct adaptived_rule_stats stats;
char config_path[FILENAME_MAX];
struct adaptived_ctx *ctx;
uint32_t trigger_cnt;
int ret;

snprintf(config_path, FILENAME_MAX - 1, "%s/010-snooze_effect.json", argv[1]);
Expand Down
3 changes: 1 addition & 2 deletions adaptived/tests/ftests/013-adaptived-asynchronous_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ int main(int argc, char *argv[])
char config_path[FILENAME_MAX];
pthread_t adaptived_thread;
struct adaptived_ctx *ctx;
uint32_t loop_cnt;
double time_diff;
void *tret;
int ret;
Expand Down Expand Up @@ -122,7 +121,7 @@ int main(int argc, char *argv[])
if (ret)
goto err;
if (stats.loops_run_cnt != 3) {
adaptived_err("Expected 3 loops, but %d loops ran\n", loop_cnt);
adaptived_err("Expected 3 loops, but %d loops ran\n", stats.loops_run_cnt);
goto err;
}

Expand Down
2 changes: 1 addition & 1 deletion adaptived/tests/ftests/015-load_rule_at_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ char *get_current_time(void)
int main(int argc, char *argv[])
{
struct adaptived_rule_stats stats;
uint32_t loop_cnt, rule_cnt;
uint32_t rule_cnt;
struct adaptived_effect *eff;
struct adaptived_cause *cse;
struct adaptived_rule *rule;
Expand Down
2 changes: 1 addition & 1 deletion adaptived/tests/ftests/016-unload_rule_at_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ char *get_current_time(void)
int main(int argc, char *argv[])
{
struct adaptived_rule_stats stats;
uint32_t loop_cnt, rule_cnt;
uint32_t rule_cnt;
struct adaptived_effect *eff;
struct adaptived_cause *cse;
struct adaptived_rule *rule;
Expand Down
2 changes: 0 additions & 2 deletions adaptived/tests/ftests/025-effect-cgroup_setting_by_psi_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ static int cgroup_files_contents[] = {
1000,
1000
};
static const int cgroup_files_contents_cnt = ARRAY_SIZE(cgroup_files_contents);
static_assert(ARRAY_SIZE(cgroup_files_contents) == ARRAY_SIZE(cgroup_files),
"cgroup file contents array must be same length as cgroup files array");

Expand All @@ -123,7 +122,6 @@ static int expected_cgroup_files_contents[] = {
999,
1000
};
static const int expected_cgroup_files_contents_cnt = ARRAY_SIZE(expected_cgroup_files_contents);
static_assert(ARRAY_SIZE(expected_cgroup_files_contents) == ARRAY_SIZE(cgroup_files),
"expected cgroup file contents array must be same length as cgroup files array");

Expand Down
2 changes: 0 additions & 2 deletions adaptived/tests/ftests/026-effect-cgroup_setting_by_psi_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ static int cgroup_files_contents[] = {
1000,
1000
};
static const int cgroup_files_contents_cnt = ARRAY_SIZE(cgroup_files_contents);
static_assert(ARRAY_SIZE(cgroup_files_contents) == ARRAY_SIZE(cgroup_files),
"cgroup file contents array must be same length as cgroup files array");

Expand All @@ -124,7 +123,6 @@ static int expected_cgroup_files_contents[] = {
1000,
1003
};
static const int expected_cgroup_files_contents_cnt = ARRAY_SIZE(expected_cgroup_files_contents);
static_assert(ARRAY_SIZE(expected_cgroup_files_contents) == ARRAY_SIZE(cgroup_files),
"expected cgroup file contents array must be same length as cgroup files array");

Expand Down
2 changes: 0 additions & 2 deletions adaptived/tests/ftests/027-effect-cgroup_setting_by_psi_3.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ static int cgroup_files_contents[] = {
100,
100
};
static const int cgroup_files_contents_cnt = ARRAY_SIZE(cgroup_files_contents);
static_assert(ARRAY_SIZE(cgroup_files_contents) == ARRAY_SIZE(cgroup_files),
"cgroup file contents array must be same length as cgroup files array");

Expand All @@ -117,7 +116,6 @@ static int expected_cgroup_files_contents[] = {
100,
75
};
static const int expected_cgroup_files_contents_cnt = ARRAY_SIZE(expected_cgroup_files_contents);
static_assert(ARRAY_SIZE(expected_cgroup_files_contents) == ARRAY_SIZE(cgroup_files),
"expected cgroup file contents array must be same length as cgroup files array");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#define EXPECTED_RET_FAIL 1

static const char * const cgroup_file = "./test045.cgroup";
static const long long expected_value = 25;

int main(int argc, char *argv[])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main(int argc, char *argv[])
{
char config_path[FILENAME_MAX];
struct adaptived_ctx *ctx = NULL;
int ret, fd, items;
int ret;
struct sysinfo info;
sysinfo(&info);
int br;
Expand Down Expand Up @@ -98,7 +98,7 @@ int main(int argc, char *argv[])
memset(buf, 0, FILENAME_MAX);
strcpy(buf, line);
/* MemTotal: 527700340 kB */
items = sscanf(buf, "MemTotal: %lld kB", &memtotal);
sscanf(buf, "MemTotal: %lld kB", &memtotal);
memtotal *= 1024;

expected_value = memtotal - 1024;
Expand Down
1 change: 0 additions & 1 deletion adaptived/tests/ftests/061-cause-top_cpu_gt.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ static int inject(struct adaptived_ctx * const ctx)
if (w <= 0)
ret = -errno;

err:
close(fd);
ctr++;

Expand Down
1 change: 0 additions & 1 deletion adaptived/tests/ftests/062-cause-top_cpu_lt.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ static int inject(struct adaptived_ctx * const ctx)
if (w <= 0)
ret = -errno;

err:
close(fd);
ctr++;

Expand Down
2 changes: 1 addition & 1 deletion adaptived/tests/ftests/063-cause-top_mem_gt.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ int main(int argc, char *argv[])
{
char config_path[FILENAME_MAX];
struct adaptived_ctx *ctx;
int ret;
int ret = -EINVAL;

snprintf(config_path, FILENAME_MAX - 1, "%s/063-cause-top_mem_gt.json", argv[1]);
config_path[FILENAME_MAX - 1] = '\0';
Expand Down
2 changes: 1 addition & 1 deletion adaptived/tests/ftests/064-cause-top_mem_lt.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ int main(int argc, char *argv[])
{
char config_path[FILENAME_MAX];
struct adaptived_ctx *ctx;
int ret;
int ret = -EINVAL;

snprintf(config_path, FILENAME_MAX - 1, "%s/064-cause-top_mem_lt.json", argv[1]);
config_path[FILENAME_MAX - 1] = '\0';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ int main(int argc, char *argv[])
{
char config_path[FILENAME_MAX];
struct adaptived_ctx *ctx;
int ret, items, br;
int ret, br;
char buf[FILENAME_MAX];
long long memtotal, val;
FILE *fp;
Expand Down Expand Up @@ -153,7 +153,7 @@ int main(int argc, char *argv[])
memset(buf, 0, FILENAME_MAX);
strcpy(buf, line);
/* MemTotal: 527700340 kB */
items = sscanf(buf, "MemTotal: %lld kB", &memtotal);
sscanf(buf, "MemTotal: %lld kB", &memtotal);
memtotal *= 1024;

val = strtol(maxbuf, 0, 0);
Expand Down
6 changes: 1 addition & 5 deletions adaptived/tests/ftests/067-effect-kill_processes.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,9 @@ int execute(int count)

int wait_pids(int count, int expected_alive_count)
{
int i, ret;
int alive_count = 0;
int killed_by_effect = 0;
pid_t killed[PID_COUNT] = { -1 };
int i;

for (i = 0; i < count; i++) {
if (pid[i] > 0) {
Expand All @@ -173,7 +172,6 @@ int wait_pids(int count, int expected_alive_count)
} while (ret == 0 && loops++ < ALIVE_TIME);
if (ret == 0) {
kill(pid[i], SIGKILL);
killed[i] = pid[i];
alive_count++;
}
adaptived_dbg("wait_pids: pid[%d]=%d, status=%d, ret=%d\n",
Expand Down Expand Up @@ -201,10 +199,8 @@ int wait_pids(int count, int expected_alive_count)
int main(int argc, char *argv[])
{
char config_path[FILENAME_MAX];
char cmdline[FILENAME_MAX];
struct adaptived_ctx *ctx;
int ret;
int i;

snprintf(config_path, FILENAME_MAX - 1, "%s/067-effect-kill_processes.json", argv[1]);
config_path[FILENAME_MAX - 1] = '\0';
Expand Down
6 changes: 1 addition & 5 deletions adaptived/tests/ftests/068-effect-kill_processes_rss.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ int execute(int count)

int wait_pids(int count, int expected_alive_count)
{
int i, ret;
int i;
int alive_count = 0;
int killed_by_effect = 0;
pid_t killed[PID_COUNT] = { -1 };

for (i = 0; i < count; i++) {
if (pid[i] > 0) {
Expand All @@ -131,7 +130,6 @@ int wait_pids(int count, int expected_alive_count)
} while (ret == 0 && loops++ < ALIVE_TIME);
if (ret == 0) {
kill(pid[i], SIGKILL);
killed[i] = pid[i];
alive_count++;
}
adaptived_dbg("wait_pids: pid[%d]=%d, status=%d, ret=%d\n",
Expand Down Expand Up @@ -159,10 +157,8 @@ int wait_pids(int count, int expected_alive_count)
int main(int argc, char *argv[])
{
char config_path[FILENAME_MAX];
char cmdline[FILENAME_MAX];
struct adaptived_ctx *ctx;
int ret;
int i;

snprintf(config_path, FILENAME_MAX - 1, "%s/068-effect-kill_processes_rss.json", argv[1]);
config_path[FILENAME_MAX - 1] = '\0';
Expand Down
5 changes: 2 additions & 3 deletions adaptived/tests/ftests/069-effect-signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int execute(pid_t * const child_pid)
{
char cmdline[FILENAME_MAX];
char *argv[2] = { NULL };
int i, ret = 0, fd;
int ret = 0, fd;

memset(cmdline, 0, FILENAME_MAX);

Expand Down Expand Up @@ -123,9 +123,8 @@ int execute(pid_t * const child_pid)
int main(int argc, char *argv[])
{
char config_path[FILENAME_MAX];
char cmdline[FILENAME_MAX];
struct adaptived_ctx *ctx;
int ret, i, status;
int ret, status;
pid_t child_pid;

snprintf(config_path, FILENAME_MAX - 1, "%s/069-effect-signal.json", argv[1]);
Expand Down
18 changes: 8 additions & 10 deletions adaptived/tests/ftests/1003-sudo-effect-sd_bus_setting-CPUQuota.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ static const int expected_period = 1000000;

int main(int argc, char *argv[])
{
char *cgrp_path = NULL, *cgrp_file = NULL;
char *cgrp_path = NULL;
char config_path[FILENAME_MAX];
char expected_buf[FILENAME_MAX];
char cgrp_file[FILENAME_MAX];
struct adaptived_ctx *ctx = NULL;
int ret, version, read_value;
FILE * fp;
Expand Down Expand Up @@ -88,10 +89,8 @@ int main(int argc, char *argv[])
goto err;

len = strlen(cgrp_path) + 1 + strlen("cpu.cfs_period_us") + 1;
cgrp_file = malloc(sizeof(char) * len);

memset(cgrp_file, 0, sizeof(cgrp_file));

sprintf(cgrp_file, "%s/cpu.cfs_period_us", cgrp_path);

fp = fopen(cgrp_file, "r");
Expand All @@ -100,6 +99,8 @@ int main(int argc, char *argv[])

read = getline(&line, &len, fp);
fclose(fp);
if (read < 0 || !line)
goto err;

read_value = atoi(line);
if (read_value < 1)
Expand All @@ -109,7 +110,6 @@ int main(int argc, char *argv[])
goto err;

memset(cgrp_file, 0, sizeof(cgrp_file));

sprintf(cgrp_file, "%s/cpu.cfs_quota_us", cgrp_path);

fp = fopen(cgrp_file, "r");
Expand All @@ -118,6 +118,8 @@ int main(int argc, char *argv[])

read = getline(&line, &len, fp);
fclose(fp);
if (read < 0 || !line)
goto err;

read_value = atoi(line);
if (read_value < 1)
Expand All @@ -133,10 +135,8 @@ int main(int argc, char *argv[])
sprintf(expected_buf, "%d %d\n", expected_quota, expected_period);

len = strlen(cgrp_path) + 1 + strlen("cpu.max") + 1;
cgrp_file = malloc(sizeof(char) * len);

memset(cgrp_file, 0, sizeof(cgrp_file));

sprintf(cgrp_file, "%s/cpu.max", cgrp_path);

fp = fopen(cgrp_file, "r");
Expand All @@ -145,6 +145,8 @@ int main(int argc, char *argv[])

read = getline(&line, &len, fp);
fclose(fp);
if (read < 0 || !line)
goto err;

if (strcmp(line, expected_buf) != 0) {
adaptived_err("sudo1003: got %s, expected %s\n", line, expected_buf);
Expand All @@ -156,8 +158,6 @@ int main(int argc, char *argv[])
free(line);
adaptived_release(&ctx);
stop_transient(cgroup_slice_name);
if (cgrp_file)
free(cgrp_file);
if (cgrp_path)
free(cgrp_path);

Expand All @@ -168,8 +168,6 @@ int main(int argc, char *argv[])
free(line);
adaptived_release(&ctx);
stop_transient(cgroup_slice_name);
if (cgrp_file)
free(cgrp_file);
if (cgrp_path)
free(cgrp_path);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main(int argc, char *argv[])
char *cgrp_path = NULL, *cgrp_file = NULL;
char config_path[FILENAME_MAX];
struct adaptived_ctx *ctx = NULL;
int ret, items, version;
int ret, version;
int br;
char buf[FILENAME_MAX];
long long memtotal;
Expand Down Expand Up @@ -92,7 +92,7 @@ int main(int argc, char *argv[])
memset(buf, 0, FILENAME_MAX);
strcpy(buf, line);
/* MemTotal: 527700340 kB */
items = sscanf(buf, "MemTotal: %lld kB", &memtotal);
sscanf(buf, "MemTotal: %lld kB", &memtotal);
memtotal *= 1024;

expected_value = memtotal - 4096;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ int main(int argc, char *argv[])
char config_path[FILENAME_MAX];
struct adaptived_ctx *ctx = NULL;
int ret, version;
int i = 0;
int max_retries = 10;

snprintf(config_path, FILENAME_MAX - 1, "%s/1006-sudo-effect-sd_bus_setting_set_int_scope.json", argv[1]);
config_path[FILENAME_MAX - 1] = '\0';
Expand Down
3 changes: 1 addition & 2 deletions adaptived/tests/ftests/ftests.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ int stop_transient(const char *transient_name)
adaptived_dbg("stop_transient: %s, ret=%d\n", cmdline, ret);
}

err:
if (cgrp_path)
free(cgrp_path);
return 0;
Expand Down Expand Up @@ -617,7 +616,7 @@ int start_unit(const char *unit_name, const char *cmd_to_run)
char cmdline[FILENAME_MAX];
char cmdbuf[FILENAME_MAX];
char *cgrp_path, *tmp_path;
int i, len;
int i = 0, len;
int max_retries = 10;
int ret;

Expand Down
4 changes: 2 additions & 2 deletions adaptived/tests/gunit/001-adaptived_get_pressure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ class AdaptivedGetPressureTest : public ::testing::Test {
ASSERT_GT(fd, 0);

ret = write(fd, SOME_LINE, strlen(SOME_LINE));
ASSERT_EQ(ret, strlen(SOME_LINE));
ASSERT_EQ(ret, (int)strlen(SOME_LINE));
ret = write(fd, FULL_LINE, strlen(FULL_LINE));
ASSERT_EQ(ret, strlen(FULL_LINE));
ASSERT_EQ(ret, (int)strlen(FULL_LINE));

close(fd);
}
Expand Down
Loading

0 comments on commit 89b8751

Please sign in to comment.