Skip to content

Commit

Permalink
ztest: improve some tests
Browse files Browse the repository at this point in the history
This commit changes some tests from using zassert_equal to validate
the pointers to using the zassert_is_null and zassert_not_null.

Signed-off-by: Michał Barnaś <[email protected]>
  • Loading branch information
barnas-michal authored and nashif committed Sep 9, 2022
1 parent dae8efa commit 1ea41b3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions tests/kernel/device/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ ZTEST(device, test_dummy_device)

/* Validates device binding for a non-existing device object */
dev = device_get_binding(DUMMY_PORT_1);
zassert_equal(dev, NULL);
zassert_is_null(dev);

/* Validates device binding for an existing device object */
dev = device_get_binding(DUMMY_PORT_2);
zassert_false((dev == NULL));
zassert_not_null(dev);

/* device_get_binding() returns false for device object
* with failed init.
*/
dev = device_get_binding(BAD_DRIVER);
zassert_true((dev == NULL));
zassert_is_null(dev);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/kernel/lifo/lifo_usage/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,13 @@ ZTEST(lifo_usage_1cpu, test_timeout_empty_lifo)

packet = k_lifo_get(&lifo_timeout[0], K_MSEC(timeout));

zassert_equal(packet, NULL);
zassert_is_null(packet);

zassert_true(is_timeout_in_range(start_time, timeout));

/* Test empty lifo with timeout of K_NO_WAIT */
packet = k_lifo_get(&lifo_timeout[0], K_NO_WAIT);
zassert_equal(packet, NULL);
zassert_is_null(packet);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/devicetree/devices/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ ZTEST(devicetree_devices, test_get_or_null)
zassert_not_equal(dev, NULL, NULL);

dev = DEVICE_DT_GET_OR_NULL(non_existing_node);
zassert_equal(dev, NULL);
zassert_is_null(dev);
}

ZTEST(devicetree_devices, test_supports)
Expand Down
30 changes: 15 additions & 15 deletions tests/lib/mpsc_pbuf/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void item_put_no_overwrite(bool pow2)

}

zassert_equal(mpsc_pbuf_claim(&buffer), NULL);
zassert_is_null(mpsc_pbuf_claim(&buffer));
}

ZTEST(log_buffer, test_item_put_no_overwrite)
Expand Down Expand Up @@ -196,7 +196,7 @@ void item_put_saturate(bool pow2)
mpsc_pbuf_free(&buffer, &t->item);
}

zassert_equal(mpsc_pbuf_claim(&buffer), NULL);
zassert_is_null(mpsc_pbuf_claim(&buffer));
}

ZTEST(log_buffer, test_item_put_saturate)
Expand Down Expand Up @@ -237,7 +237,7 @@ void benchmark_item_put(bool pow2)
t = get_cyc() - t;
PRINT("single word item claim,free: %d cycles\n", t/repeat);

zassert_equal(mpsc_pbuf_claim(&buffer), NULL);
zassert_is_null(mpsc_pbuf_claim(&buffer));
}

ZTEST(log_buffer, test_benchmark_item_put)
Expand Down Expand Up @@ -275,7 +275,7 @@ void item_put_ext_no_overwrite(bool pow2)
mpsc_pbuf_free(&buffer, &t->item);
}

zassert_equal(mpsc_pbuf_claim(&buffer), NULL);
zassert_is_null(mpsc_pbuf_claim(&buffer));
}

ZTEST(log_buffer, test_item_put_ext_no_overwrite)
Expand Down Expand Up @@ -363,7 +363,7 @@ void item_put_ext_saturate(bool pow2)
mpsc_pbuf_free(&buffer, &t->item);
}

zassert_equal(mpsc_pbuf_claim(&buffer), NULL);
zassert_is_null(mpsc_pbuf_claim(&buffer));
}

ZTEST(log_buffer, test_item_put_ext_saturate)
Expand Down Expand Up @@ -410,7 +410,7 @@ void benchmark_item_put_ext(bool pow2)
t = get_cyc() - t;
PRINT("ext item claim,free: %d cycles\n", t/repeat);

zassert_equal(mpsc_pbuf_claim(&buffer), NULL);
zassert_is_null(mpsc_pbuf_claim(&buffer));
}

ZTEST(log_buffer, test_benchmark_item_put_ext)
Expand Down Expand Up @@ -461,7 +461,7 @@ void benchmark_item_put_data(bool pow2)
t = get_cyc() - t;
PRINT("ext item claim,free: %d cycles\n", t/repeat);

zassert_equal(mpsc_pbuf_claim(&buffer), NULL);
zassert_is_null(mpsc_pbuf_claim(&buffer));
}

ZTEST(log_buffer, test_benchmark_item_put_data)
Expand Down Expand Up @@ -635,7 +635,7 @@ void item_alloc_commit_saturate(bool pow2)

packet = (struct test_data_var *)mpsc_pbuf_alloc(&buffer, len,
K_NO_WAIT);
zassert_equal(packet, NULL);
zassert_is_null(packet);

/* Get one packet from the buffer. */
packet = (struct test_data_var *)mpsc_pbuf_claim(&buffer);
Expand Down Expand Up @@ -670,7 +670,7 @@ void item_alloc_preemption(bool pow2)

/* Check that no packet is yet available */
p = (struct test_data_var *)mpsc_pbuf_claim(&buffer);
zassert_equal(p, NULL);
zassert_is_null(p);

p1 = (struct test_data_var *)mpsc_pbuf_alloc(&buffer, 20, K_NO_WAIT);
zassert_true(p1);
Expand All @@ -683,7 +683,7 @@ void item_alloc_preemption(bool pow2)

/* Check that no packet is yet available */
p = (struct test_data_var *)mpsc_pbuf_claim(&buffer);
zassert_equal(p, NULL);
zassert_is_null(p);

mpsc_pbuf_commit(&buffer, (union mpsc_pbuf_generic *)p0);

Expand All @@ -701,7 +701,7 @@ void item_alloc_preemption(bool pow2)

/* No more packets. */
p = (struct test_data_var *)mpsc_pbuf_claim(&buffer);
zassert_equal(p, NULL);
zassert_is_null(p);
}

ZTEST(log_buffer, test_item_alloc_preemption)
Expand Down Expand Up @@ -765,7 +765,7 @@ void overwrite(bool pow2)
mpsc_pbuf_free(&buffer, (union mpsc_pbuf_generic *)p);

p = (struct test_data_var *)mpsc_pbuf_claim(&buffer);
zassert_equal(p, NULL);
zassert_is_null(p);
}

ZTEST(log_buffer, test_overwrite)
Expand Down Expand Up @@ -818,7 +818,7 @@ void overwrite_while_claimed(bool pow2)
zassert_equal(p0->hdr.len, len);

p0 = (struct test_data_var *)mpsc_pbuf_claim(&buffer);
zassert_equal(p0, NULL);
zassert_is_null(p0);
}

ZTEST(log_buffer, test_overwrite_while_claimed)
Expand Down Expand Up @@ -875,7 +875,7 @@ void overwrite_while_claimed2(bool pow2)
zassert_equal(p0->hdr.len, len);

p0 = (struct test_data_var *)mpsc_pbuf_claim(&buffer);
zassert_equal(p0, NULL);
zassert_is_null(p0);
}

ZTEST(log_buffer, test_overwrite_while_claimed2)
Expand Down Expand Up @@ -986,7 +986,7 @@ void t_entry(void *p0, void *p1, void *p2)
t = (struct test_data_ext *)mpsc_pbuf_alloc(buffer,
sizeof(*t) / sizeof(uint32_t),
K_MSEC(1));
zassert_equal(t, NULL);
zassert_is_null(t);

t = (struct test_data_ext *)mpsc_pbuf_alloc(buffer,
sizeof(*t) / sizeof(uint32_t),
Expand Down
20 changes: 10 additions & 10 deletions tests/subsys/pm/policy_api/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ ZTEST(policy_api, test_pm_policy_next_state_default)

/* cpu 0 */
next = pm_policy_next_state(0U, 0);
zassert_equal(next, NULL);
zassert_is_null(next);

next = pm_policy_next_state(0U, k_us_to_ticks_floor32(10999));
zassert_equal(next, NULL);
zassert_is_null(next);

next = pm_policy_next_state(0U, k_us_to_ticks_floor32(110000));
zassert_equal(next->state, PM_STATE_RUNTIME_IDLE);
Expand All @@ -43,10 +43,10 @@ ZTEST(policy_api, test_pm_policy_next_state_default)

/* cpu 1 */
next = pm_policy_next_state(1U, 0);
zassert_equal(next, NULL);
zassert_is_null(next);

next = pm_policy_next_state(1U, k_us_to_ticks_floor32(549999));
zassert_equal(next, NULL);
zassert_is_null(next);

next = pm_policy_next_state(1U, k_us_to_ticks_floor32(550000));
zassert_equal(next->state, PM_STATE_SUSPEND_TO_RAM);
Expand Down Expand Up @@ -84,7 +84,7 @@ ZTEST(policy_api, test_pm_policy_next_state_default_allowed)
zassert_true(active);

next = pm_policy_next_state(0U, k_us_to_ticks_floor32(110000));
zassert_equal(next, NULL);
zassert_is_null(next);

/* allow PM_STATE_RUNTIME_IDLE again
* next state: PM_STATE_RUNTIME_IDLE
Expand Down Expand Up @@ -115,7 +115,7 @@ ZTEST(policy_api, test_pm_policy_next_state_default_allowed)
zassert_true(active);

next = pm_policy_next_state(0U, k_us_to_ticks_floor32(110000));
zassert_equal(next, NULL);
zassert_is_null(next);

/* allow PM_STATE_RUNTIME_IDLE and substate 1 again
* next state: PM_STATE_RUNTIME_IDLE
Expand Down Expand Up @@ -162,10 +162,10 @@ ZTEST(policy_api, test_pm_policy_next_state_default_latency)
pm_policy_latency_request_add(&req1, 9000);

next = pm_policy_next_state(0U, k_us_to_ticks_floor32(110000));
zassert_equal(next, NULL);
zassert_is_null(next);

next = pm_policy_next_state(0U, k_us_to_ticks_floor32(1100000));
zassert_equal(next, NULL);
zassert_is_null(next);

/* update latency requirement to a value between latencies for
* PM_STATE_RUNTIME_IDLE and PM_STATE_SUSPEND_TO_RAM, so we should
Expand All @@ -186,10 +186,10 @@ ZTEST(policy_api, test_pm_policy_next_state_default_latency)
pm_policy_latency_request_add(&req2, 8000);

next = pm_policy_next_state(0U, k_us_to_ticks_floor32(110000));
zassert_equal(next, NULL);
zassert_is_null(next);

next = pm_policy_next_state(0U, k_us_to_ticks_floor32(1100000));
zassert_equal(next, NULL);
zassert_is_null(next);

/* remove previous request, so we should recover behavior given by
* first request.
Expand Down

0 comments on commit 1ea41b3

Please sign in to comment.