1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12 /*
13 * Copyright 2024 Oxide Computer Company
14 */
15
16 /*
17 * Basic test of libjedec temperature features.
18 */
19
20 #include <stdlib.h>
21 #include <limits.h>
22 #include <err.h>
23 #include <sys/sysmacros.h>
24 #include <libjedec.h>
25
26 typedef struct {
27 uint32_t ltt_temp;
28 boolean_t ltt_res;
29 int32_t ltt_min;
30 int32_t ltt_max;
31 const char *ltt_desc;
32 } libjedec_temp_test_t;
33
34 static const libjedec_temp_test_t temp_tests[] = {
35 { JEDEC_TEMP_CASE_A2T, B_TRUE, -40, 105, "Operating temperature A2T" },
36 { JEDEC_TEMP_CASE_RT, B_TRUE, 0, 45, "Operating temperature RT" },
37 { JEDEC_TEMP_AMB_CT, B_TRUE, 0, 70, "Ambient temperature CT" },
38 { JEDEC_TEMP_AMB_IOT, B_TRUE, -40, 85, "Ambient temperature IOT" },
39 { JEDEC_TEMP_AMB_AO1T, B_TRUE, -40, 125, "Ambient temperature A01T" },
40 { JEDEC_TEMP_STOR_ST, B_TRUE, -40, 85, "Storage temperature ST" },
41 { JEDEC_TEMP_JNCT_A90, B_TRUE, -40, 90, "Junction temperature A90" },
42 { JEDEC_TEMP_JNCT_LT115, B_TRUE, -40, 115,
43 "Junction temperature LT115" },
44 { JEDEC_TEMP_JNCT_ET, B_TRUE, -25, 105, "Junction temperature ET" },
45 { JEDEC_TEMP_JNCT_XT, B_TRUE, 0, 95, "Junction temperature XT" },
46 { 142, B_FALSE, 0, 0, "invalid temperature (142)" },
47 { INT32_MAX, B_FALSE, 0, 0, "invalid temperature (INT32_MAX)" },
48 { UINT32_MAX, B_FALSE, 0, 0, "invalid temperature (UINT32_MAX)" }
49 };
50
51 static boolean_t
libjedec_temp_run_single(const libjedec_temp_test_t * test)52 libjedec_temp_run_single(const libjedec_temp_test_t *test)
53 {
54 int32_t min = INT32_MIN, max = INT32_MAX;
55 boolean_t res;
56
57 res = libjedec_temp_range(test->ltt_temp, &min, &max);
58 if (res != test->ltt_res) {
59 if (test->ltt_res) {
60 warnx("libjedec_temp_range() succeeded, but we "
61 "expected failure!");
62 } else {
63 warnx("libjedec_temp_range() failed, but we expected "
64 "success!");
65 }
66 return (B_FALSE);
67 }
68
69 if (!res) {
70 return (B_TRUE);
71 }
72
73 if (min != test->ltt_min) {
74 warnx("received incorrect minimum temperature: expected %d, "
75 "found %d\n", test->ltt_min, min);
76 }
77
78 if (max != test->ltt_max) {
79 warnx("received incorrect maximum temperature: expected %d, "
80 "found %d\n", test->ltt_max, max);
81 }
82
83 return (B_TRUE);
84 }
85
86 int
main(void)87 main(void)
88 {
89 int ret = EXIT_SUCCESS;
90
91 for (size_t i = 0; i < ARRAY_SIZE(temp_tests); i++) {
92 const libjedec_temp_test_t *test = &temp_tests[i];
93
94 if (libjedec_temp_run_single(test)) {
95 (void) printf("TEST PASSED: %s\n", test->ltt_desc);
96 } else {
97 (void) fprintf(stderr, "TEST FAILED: %s\n",
98 test->ltt_desc);
99 ret = EXIT_FAILURE;
100 }
101 }
102
103 if (ret == EXIT_SUCCESS) {
104 (void) printf("All tests passed successfully!\n");
105 }
106
107 return (ret);
108 }
109