Skip to content

Commit

Permalink
unittest: Fix c99 compiler error
Browse files Browse the repository at this point in the history
Remove variable declaration in for loops.

Signed-off-by: Clément Guidi <[email protected]>
  • Loading branch information
clementguidi authored and namhyung committed Mar 8, 2023
1 parent 05491d2 commit 9e0ae4a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions misc/bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ int bar(volatile int *ptr)
int bench(int count)
{
volatile int result = 0;
int i;

for (int i = 0; i < count; i++) {
for (i = 0; i < count; i++) {
if (i % 2 == 0)
foo(&result);
else
Expand All @@ -33,6 +34,7 @@ int bench(int count)
int main(int argc, char *argv[])
{
int n = 1;
int i;
int loop = 1000000;
int result = 0;

Expand All @@ -41,7 +43,7 @@ int main(int argc, char *argv[])
if (argc > 2)
loop = atoi(argv[2]);

for (int i = 0; i < n; i++)
for (i = 0; i < n; i++)
result += bench(loop);

return result ? 0 : 1;
Expand Down
6 changes: 4 additions & 2 deletions utils/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ int read_events_file(struct uftrace_data *handle)

TEST_CASE(event_name)
{
unsigned i;
struct uftrace_data handle = {};
struct {
unsigned evt_id;
Expand All @@ -338,7 +339,7 @@ TEST_CASE(event_name)
};

pr_dbg("testing event name strings\n");
for (unsigned i = 0; i < ARRAY_SIZE(expected); i++) {
for (i = 0; i < ARRAY_SIZE(expected); i++) {
char *got = event_get_name(&handle, expected[i].evt_id);
TEST_STREQ(expected[i].evt_name, got);
free(got);
Expand All @@ -354,6 +355,7 @@ TEST_CASE(event_data)
struct uftrace_page_fault pgfault = { 1977, 1102 };
struct uftrace_pmu_cycle cycle = { 1024, 2048 };
int cpu = 123;
unsigned i;

struct {
unsigned evt_id;
Expand All @@ -368,7 +370,7 @@ TEST_CASE(event_data)
};

pr_dbg("testing event data strings\n");
for (unsigned i = 0; i < ARRAY_SIZE(expected); i++) {
for (i = 0; i < ARRAY_SIZE(expected); i++) {
char *got = event_get_data_str(expected[i].evt_id, expected[i].data, true);
TEST_STREQ(expected[i].str, got);
free(got);
Expand Down
3 changes: 2 additions & 1 deletion utils/extern.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,10 @@ TEST_CASE(fstack_extern_data2)
const char test_data[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456";
int msg_size = EXTERN_DATA_MAX * 2;
char *extern_data;
int i;

extern_data = xmalloc(msg_size + 1);
for (int i = 0; i < msg_size; i += sizeof(test_data) - 1)
for (i = 0; i < msg_size; i += sizeof(test_data) - 1)
strcpy(&extern_data[i], test_data);

pr_dbg("creating external data file\n");
Expand Down

0 comments on commit 9e0ae4a

Please sign in to comment.