Getting debug_get_num_option to return int64_t, as long under 64 bit Linux are 64 bit size,
so using fixed int64_t for cross platform consistence, as long under win32 is 32 bit size.
Getting DEBUG_GET_ONCE_FLAGS_OPTION to return uint64_t to getting it to be
consistence with debug_get_flags_option.
DEBUG_GET_ONCE_NUM_OPTION is not accessed in codebase, so add unittest for it, it maybe
used in future, remove it is not consistence
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19554>
EXPECT_EQ(debug_get_num_option("MESA_UNIT_TEST_NUM_VARIABLE_2", 100), 100);
}
}
+
+DEBUG_GET_ONCE_NUM_OPTION(num_once_test_0, "MESA_UNIT_TEST_DEBUG_GET_ONCE_NUM_VARIABLE_0", -33)
+
+DEBUG_GET_ONCE_NUM_OPTION(num_once_test_1, "MESA_UNIT_TEST_DEBUG_GET_ONCE_NUM_VARIABLE_1", 0)
+
+DEBUG_GET_ONCE_NUM_OPTION(num_once_test_2, "MESA_UNIT_TEST_DEBUG_GET_ONCE_NUM_VARIABLE_2", 0)
+
+TEST(u_debug, DEBUG_GET_ONCE_NUM_OPTION_Macro)
+{
+ {
+ EXPECT_EQ(debug_get_option_num_once_test_0(), -33);
+ }
+
+ {
+ static char env_str[] = "MESA_UNIT_TEST_DEBUG_GET_ONCE_NUM_VARIABLE_1=9223372036854775807";
+ putenv(env_str);
+ EXPECT_EQ(debug_get_option_num_once_test_1(), INT64_MAX);
+ }
+
+ {
+ static char env_str[] = "MESA_UNIT_TEST_DEBUG_GET_ONCE_NUM_VARIABLE_1=9223372036854775806";
+ putenv(env_str);
+ EXPECT_EQ(debug_get_option_num_once_test_1(), INT64_MAX);
+ }
+
+ {
+ static char env_str[] = "MESA_UNIT_TEST_DEBUG_GET_ONCE_NUM_VARIABLE_2=-9223372036854775808";
+ putenv(env_str);
+ EXPECT_EQ(debug_get_option_num_once_test_2(), INT64_MIN);
+ }
+}
}
-long
-debug_get_num_option(const char *name, long dfault)
+int64_t
+debug_get_num_option(const char *name, int64_t dfault)
{
- long result;
+ int64_t result;
const char *str;
str = os_get_option(name);
} else {
char *endptr;
- result = strtol(str, &endptr, 0);
+ result = strtoll(str, &endptr, 0);
if (str == endptr) {
/* Restore the default value when no digits were found. */
result = dfault;
}
if (debug_get_option_should_print())
- debug_printf("%s: %s = %li\n", __func__, name, result);
+ debug_printf("%s: %s = %"PRId64"\n", __func__, name, result);
return result;
}
const char *
debug_dump_enum(const struct debug_named_value *names,
- unsigned long value)
+ uint64_t value)
{
static char rest[64];
++names;
}
- snprintf(rest, sizeof(rest), "0x%08lx", value);
+ snprintf(rest, sizeof(rest), "0x%08"PRIx64, value);
return rest;
}
const char *
-debug_dump_flags(const struct debug_named_value *names, unsigned long value)
+debug_dump_flags(const struct debug_named_value *names, uint64_t value)
{
static char output[4096];
static char rest[256];
else
first = 0;
- snprintf(rest, sizeof(rest), "0x%08lx", value);
+ snprintf(rest, sizeof(rest), "0x%08"PRIx64, value);
strncat(output, rest, sizeof(output) - strlen(output) - 1);
output[sizeof(output) - 1] = '\0';
}
#endif /* !DEBUG */
-long
-debug_get_num_option(const char *name, long dfault);
-
void
debug_get_version_option(const char *name, unsigned *major, unsigned *minor);
* ...
* @endcode
*/
-#define DEBUG_NAMED_VALUE(__symbol) {#__symbol, (unsigned long)__symbol, NULL}
-#define DEBUG_NAMED_VALUE_WITH_DESCRIPTION(__symbol, __desc) {#__symbol, (unsigned long)__symbol, __desc}
+#define DEBUG_NAMED_VALUE(__symbol) {#__symbol, (uint64_t)__symbol, NULL}
+#define DEBUG_NAMED_VALUE_WITH_DESCRIPTION(__symbol, __desc) {#__symbol, (uint64_t)__symbol, __desc}
#define DEBUG_NAMED_VALUE_END {NULL, 0, NULL}
*/
const char *
debug_dump_enum(const struct debug_named_value *names,
- unsigned long value);
+ uint64_t value);
/**
* Convert binary flags value to a string.
*/
const char *
debug_dump_flags(const struct debug_named_value *names,
- unsigned long value);
+ uint64_t value);
struct debug_control {
bool
debug_get_bool_option(const char *name, bool dfault);
-long
-debug_get_num_option(const char *name, long dfault);
+int64_t
+debug_get_num_option(const char *name, int64_t dfault);
uint64_t
debug_get_flags_option(const char *name,
}
#define DEBUG_GET_ONCE_NUM_OPTION(sufix, name, dfault) \
-static long \
+static int64_t \
debug_get_option_ ## sufix (void) \
{ \
static bool initialized = false; \
- static long value; \
+ static int64_t value; \
if (unlikely(!p_atomic_read_relaxed(&initialized))) { \
value = debug_get_num_option(name, dfault); \
p_atomic_set(&initialized, true); \
}
#define DEBUG_GET_ONCE_FLAGS_OPTION(sufix, name, flags, dfault) \
-static unsigned long \
+static uint64_t \
debug_get_option_ ## sufix (void) \
{ \
static bool initialized = false; \
- static unsigned long value; \
+ static uint64_t value; \
if (unlikely(!p_atomic_read_relaxed(&initialized))) { \
value = debug_get_flags_option(name, flags, dfault); \
p_atomic_set(&initialized, true); \