Commit 1ea41b34 authored by Michał Barnaś's avatar Michał Barnaś Committed by Anas Nashif
Browse files

ztest: improve some tests



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: default avatarMichał Barnaś <mb@semihalf.com>
parent dae8efa6
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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);
}

/**
+2 −2
Original line number Diff line number Diff line
@@ -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);
}

/**
+1 −1
Original line number Diff line number Diff line
@@ -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)
+15 −15
Original line number Diff line number Diff line
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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);
@@ -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);
@@ -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);

@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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),
+10 −10
Original line number Diff line number Diff line
@@ -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);
@@ -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);
@@ -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
@@ -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
@@ -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
@@ -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.