]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Print the actual states in assert messages for time tracking
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 5 Mar 2024 18:11:31 +0000 (12:11 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 5 Mar 2024 18:13:08 +0000 (12:13 -0600)
src/lib/io/all.mk
src/lib/io/time_tracking.c [new file with mode: 0644]
src/lib/io/time_tracking.h

index aa1fa0852b69ffce6b029375455756b3c41b17d8..800a1b6c76a7968e7b4c777e0cb587cc1d8c316f 100644 (file)
@@ -12,6 +12,7 @@ SOURCES       := \
        queue.c \
        ring_buffer.c \
        schedule.c \
+       time_tracking.c \
        worker.c
 
 TGT_PREREQS    := libfreeradius-util$(L) $(LIBFREERADIUS_SERVER)
diff --git a/src/lib/io/time_tracking.c b/src/lib/io/time_tracking.c
new file mode 100644 (file)
index 0000000..0667f89
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * $Id$
+ *
+ * @brief Simple ring buffers for packet contents
+ * @file io/time_tracking.c
+ *
+ * @copyright 2024 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
+ */
+RCSID("$Id$")
+
+#include <freeradius-devel/io/time_tracking.h>
+
+fr_table_num_ordered_t fr_time_tracking_state_table[] = {
+       { L("STOPPED"),         FR_TIME_TRACKING_STOPPED        },
+       { L("RUNNING"),         FR_TIME_TRACKING_RUNNING        },
+       { L("YIELDED"),         FR_TIME_TRACKING_YIELDED        },
+};
+size_t fr_time_tracking_state_table_len = NUM_ELEMENTS(fr_time_tracking_state_table);
index c3dfc909a76f009e44f5332cbdc52a3103a12312..2970c8df92ff346efcd2653682027e99efa750d3 100644 (file)
@@ -31,8 +31,12 @@ extern "C" {
 #endif
 
 #include <freeradius-devel/util/debug.h>
+#include <freeradius-devel/util/table.h>
 #include <freeradius-devel/util/time.h>
 
+extern fr_table_num_ordered_t fr_time_tracking_state_table[];
+extern size_t fr_time_tracking_state_table_len;
+
 typedef enum {
        FR_TIME_TRACKING_STOPPED = 0,                           //!< Time tracking is not running.
        FR_TIME_TRACKING_RUNNING,                               //!< We're currently tracking time in the
@@ -148,7 +152,9 @@ static inline CC_HINT(nonnull) void fr_time_tracking_init(fr_time_tracking_t *tt
 static inline CC_HINT(nonnull(2)) void fr_time_tracking_start(fr_time_tracking_t *parent,
                                                           fr_time_tracking_t *tt, fr_time_t now)
 {
-       fr_assert_msg(tt->state == FR_TIME_TRACKING_STOPPED, "Unexpected time tracking state state %i", tt->state);
+
+       fr_assert_msg(tt->state == FR_TIME_TRACKING_STOPPED, "Unexpected time tracking state state %s",
+                     fr_table_str_by_value(fr_time_tracking_state_table, tt->state, "<INVALID>"));
        fr_assert(!tt->parent);
 
        ASSERT_ON_TIME_TRAVEL(tt, now);
@@ -176,7 +182,8 @@ static inline CC_HINT(nonnull) void fr_time_tracking_push(fr_time_tracking_t *pa
        fr_assert(tt->parent);
        fr_assert(parent->parent == tt->parent);
 
-       fr_assert_msg(tt->state == FR_TIME_TRACKING_RUNNING, "Unexpected time tracking state state %i", tt->state);
+       fr_assert_msg(tt->state == FR_TIME_TRACKING_RUNNING, "Unexpected time tracking state state %s",
+                     fr_table_str_by_value(fr_time_tracking_state_table, tt->state, "<INVALID>"));
        run_time = fr_time_sub(now, tt->last_changed);
        tt->last_changed = parent->started = now;
 
@@ -196,7 +203,8 @@ static inline CC_HINT(nonnull) void fr_time_tracking_pop(fr_time_tracking_t *tt,
 {
        fr_time_delta_t         run_time;
 
-       fr_assert_msg(tt->state == FR_TIME_TRACKING_RUNNING, "Unexpected time tracking state state %i", tt->state);
+       fr_assert_msg(tt->state == FR_TIME_TRACKING_RUNNING, "Unexpected time tracking state state %s",
+                     fr_table_str_by_value(fr_time_tracking_state_table, tt->state, "<INVALID>"));
        fr_assert(tt->parent);
 
        run_time = fr_time_sub(now, tt->last_changed);
@@ -219,7 +227,8 @@ static inline CC_HINT(nonnull) void fr_time_tracking_yield(fr_time_tracking_t *t
 
        ASSERT_ON_TIME_TRAVEL(tt, now);
 
-       fr_assert_msg(tt->state == FR_TIME_TRACKING_RUNNING, "Unexpected time tracking state state %i", tt->state);
+       fr_assert_msg(tt->state == FR_TIME_TRACKING_RUNNING, "Unexpected time tracking state state %s",
+                     fr_table_str_by_value(fr_time_tracking_state_table, tt->state, "<INVALID>"));
        tt->state = FR_TIME_TRACKING_YIELDED;
        tt->last_yielded = tt->last_changed = now;
 
@@ -239,7 +248,8 @@ static inline CC_HINT(nonnull) void fr_time_tracking_resume(fr_time_tracking_t *
 
        ASSERT_ON_TIME_TRAVEL(tt, now);
 
-       fr_assert_msg(tt->state == FR_TIME_TRACKING_YIELDED, "Unexpected time tracking state state %i", tt->state);
+       fr_assert_msg(tt->state == FR_TIME_TRACKING_YIELDED, "Unexpected time tracking state state %s",
+                     fr_table_str_by_value(fr_time_tracking_state_table, tt->state, "<INVALID>"));
        tt->state = FR_TIME_TRACKING_RUNNING;
        tt->last_resumed = tt->last_changed = now;
 
@@ -262,7 +272,8 @@ static inline void fr_time_tracking_end(fr_time_delta_t *predicted,
 {
        fr_time_delta_t         run_time;
 
-       fr_assert_msg(tt->state == FR_TIME_TRACKING_RUNNING, "Unexpected time tracking state state %i", tt->state);
+       fr_assert_msg(tt->state == FR_TIME_TRACKING_RUNNING, "Unexpected time tracking state state %s",
+                     fr_table_str_by_value(fr_time_tracking_state_table, tt->state, "<INVALID>"));
        ASSERT_ON_TIME_TRAVEL(tt, now);
 
        tt->state = FR_TIME_TRACKING_STOPPED;