Change in osmo-bsc[master]: handover_test: add fake-time 'wait'

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

neels gerrit-no-reply at lists.osmocom.org
Thu Jul 15 09:28:20 UTC 2021


neels has submitted this change. ( https://gerrit.osmocom.org/c/osmo-bsc/+/24933 )

Change subject: handover_test: add fake-time 'wait'
......................................................................

handover_test: add fake-time 'wait'

Add a 'wait' cmd that lets (fake) time pass.

An ucoming patch will show the
first use of this: "test_penalty_timer.ho_vty: show lchan recovery"
I8f7668b6d08a0dac9e90d2358955f9d5099d39fa

My actual original reason to add this follows in patches
- "handover tests: test passing of penalty timeout"
  I65e59cc7309778cf9d71612669ce84d101c8135e
- "hodec2: add low-rxqual-assignment penalty timer (2/2)"
  Id00a07313fe04eec509b336c0637b59c707760e0

Related: SYS#5198
Change-Id: Ia6b5696adef7e7bf649473b4d79b96acf3aa59e3
---
M tests/handover/handover_test.c
1 file changed, 56 insertions(+), 0 deletions(-)

Approvals:
  daniel: Looks good to me, approved
  pespin: Looks good to me, but someone else must approve
  Jenkins Builder: Verified



diff --git a/tests/handover/handover_test.c b/tests/handover/handover_test.c
index 60a31be..331726a 100644
--- a/tests/handover/handover_test.c
+++ b/tests/handover/handover_test.c
@@ -94,6 +94,41 @@
 	uint8_t bcch_f;
 };
 
+const struct timeval fake_time_start_time = { 123, 456 };
+
+void fake_time_passes(time_t secs, suseconds_t usecs)
+{
+	struct timeval diff;
+	/* Add time to osmo_fsm timers, using osmo_gettimeofday() */
+	osmo_gettimeofday_override_add(secs, usecs);
+	/* Add time to penalty timers, using osmo_clock_gettime() */
+	osmo_clock_override_add(CLOCK_MONOTONIC, secs, usecs * 1000);
+
+	timersub(&osmo_gettimeofday_override_time, &fake_time_start_time, &diff);
+	fprintf(stderr, "Total time passed: %d.%06d s\n", (int)diff.tv_sec, (int)diff.tv_usec);
+
+	osmo_timers_prepare();
+	osmo_timers_update();
+}
+
+void fake_time_start()
+{
+	struct timespec *clock_override;
+
+	/* osmo_fsm uses osmo_gettimeofday(). To affect FSM timeouts, we need osmo_gettimeofday_override. */
+	osmo_gettimeofday_override_time = fake_time_start_time;
+	osmo_gettimeofday_override = true;
+
+	/* Penalty timers use osmo_clock_gettime(CLOCK_MONOTONIC). To affect these timeouts, we need
+	 * osmo_gettimeofday_override. */
+	clock_override = osmo_clock_override_gettimespec(CLOCK_MONOTONIC);
+	OSMO_ASSERT(clock_override);
+	clock_override->tv_sec = fake_time_start_time.tv_sec;
+	clock_override->tv_nsec = fake_time_start_time.tv_usec * 1000;
+	osmo_clock_override_enable(CLOCK_MONOTONIC, true);
+	fake_time_passes(0, 0);
+}
+
 static void gen_meas_rep(struct gsm_lchan *lchan,
 			 uint8_t bs_power_db, uint8_t rxlev, uint8_t rxqual, uint8_t ta,
 			 int neighbors_count, struct neighbor_meas *neighbors)
@@ -1410,6 +1445,22 @@
 	return CMD_SUCCESS;
 }
 
+DEFUN(wait, wait_cmd,
+	"wait <0-999999> [<0-999>]",
+	"Let some fake time pass. The test continues instantaneously, but this overrides osmo_gettimeofday() to let"
+	" given amount of time pass virtually.\n"
+	"Seconds to fake-wait\n"
+	"Microseconds to fake-wait, in addition to the seconds waited\n")
+{
+	time_t seconds = atoi(argv[0]);
+	suseconds_t useconds = 0;
+	VTY_ECHO();
+	if (argc > 1)
+		useconds = atoi(argv[1]) * 1000;
+	fake_time_passes(seconds, useconds);
+	return CMD_SUCCESS;
+}
+
 static void ho_test_vty_init()
 {
 	install_element(CONFIG_NODE, &create_n_bts_cmd);
@@ -1433,6 +1484,7 @@
 	install_element(CONFIG_NODE, &codec_f_cmd);
 	install_element(CONFIG_NODE, &codec_h_cmd);
 	install_element(CONFIG_NODE, &set_ts_use_cmd);
+	install_element(CONFIG_NODE, &wait_cmd);
 }
 
 static const struct log_info_cat log_categories[] = {
@@ -1554,6 +1606,10 @@
 	log_set_print_timestamp(osmo_stderr_target, 0);
 	osmo_fsm_log_addr(false);
 
+	/* the 'wait' command above, intended to test penalty timers, adds seconds to the monotonic clock in "fake
+	 * time". */
+	fake_time_start();
+
 	bsc_network_alloc();
 	if (!bsc_gsmnet)
 		exit(1);

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/24933
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: Ia6b5696adef7e7bf649473b4d79b96acf3aa59e3
Gerrit-Change-Number: 24933
Gerrit-PatchSet: 3
Gerrit-Owner: neels <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: neels <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210715/1a28ed8a/attachment.htm>


More information about the gerrit-log mailing list