adi-test.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * selftest for sparc64's privileged ADI driver
  4. *
  5. * Author: Tom Hromatka <tom.hromatka@oracle.com>
  6. */
  7. #include <linux/kernel.h>
  8. #include <errno.h>
  9. #include <fcntl.h>
  10. #include <stdarg.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <sys/syscall.h>
  15. #include <sys/types.h>
  16. #include <sys/stat.h>
  17. #include <unistd.h>
  18. #include "../../kselftest.h"
  19. #define DEBUG_LEVEL_1_BIT (0x0001)
  20. #define DEBUG_LEVEL_2_BIT (0x0002)
  21. #define DEBUG_LEVEL_3_BIT (0x0004)
  22. #define DEBUG_LEVEL_4_BIT (0x0008)
  23. #define DEBUG_TIMING_BIT (0x1000)
  24. #ifndef ARRAY_SIZE
  25. # define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  26. #endif
  27. /* bit mask of enabled bits to print */
  28. #define DEBUG 0x0001
  29. #define DEBUG_PRINT_L1(...) debug_print(DEBUG_LEVEL_1_BIT, __VA_ARGS__)
  30. #define DEBUG_PRINT_L2(...) debug_print(DEBUG_LEVEL_2_BIT, __VA_ARGS__)
  31. #define DEBUG_PRINT_L3(...) debug_print(DEBUG_LEVEL_3_BIT, __VA_ARGS__)
  32. #define DEBUG_PRINT_L4(...) debug_print(DEBUG_LEVEL_4_BIT, __VA_ARGS__)
  33. #define DEBUG_PRINT_T(...) debug_print(DEBUG_TIMING_BIT, __VA_ARGS__)
  34. static void debug_print(int level, const char *s, ...)
  35. {
  36. va_list args;
  37. va_start(args, s);
  38. if (DEBUG & level)
  39. vfprintf(stdout, s, args);
  40. va_end(args);
  41. }
  42. #ifndef min
  43. #define min(x, y) ((x) < (y) ? x : y)
  44. #endif
  45. #define RETURN_FROM_TEST(_ret) \
  46. do { \
  47. DEBUG_PRINT_L1( \
  48. "\tTest %s returned %d\n", __func__, _ret); \
  49. return _ret; \
  50. } while (0)
  51. #define ADI_BLKSZ 64
  52. #define ADI_MAX_VERSION 15
  53. #define TEST_STEP_FAILURE(_ret) \
  54. do { \
  55. fprintf(stderr, "\tTest step failure: %d at %s:%d\n", \
  56. _ret, __func__, __LINE__); \
  57. goto out; \
  58. } while (0)
  59. #define RDTICK(_x) \
  60. asm volatile(" rd %%tick, %0\n" : "=r" (_x))
  61. static int random_version(void)
  62. {
  63. long tick;
  64. RDTICK(tick);
  65. return tick % (ADI_MAX_VERSION + 1);
  66. }
  67. #define MAX_RANGES_SUPPORTED 5
  68. static const char system_ram_str[] = "System RAM\n";
  69. static int range_count;
  70. static unsigned long long int start_addr[MAX_RANGES_SUPPORTED];
  71. static unsigned long long int end_addr[MAX_RANGES_SUPPORTED];
  72. struct stats {
  73. char name[16];
  74. unsigned long total;
  75. unsigned long count;
  76. unsigned long bytes;
  77. };
  78. static struct stats read_stats = {
  79. .name = "read", .total = 0, .count = 0, .bytes = 0};
  80. static struct stats pread_stats = {
  81. .name = "pread", .total = 0, .count = 0, .bytes = 0};
  82. static struct stats write_stats = {
  83. .name = "write", .total = 0, .count = 0, .bytes = 0};
  84. static struct stats pwrite_stats = {
  85. .name = "pwrite", .total = 0, .count = 0, .bytes = 0};
  86. static struct stats seek_stats = {
  87. .name = "seek", .total = 0, .count = 0, .bytes = 0};
  88. static void update_stats(struct stats * const ustats,
  89. unsigned long measurement, unsigned long bytes)
  90. {
  91. ustats->total += measurement;
  92. ustats->bytes += bytes;
  93. ustats->count++;
  94. }
  95. static void print_ustats(const struct stats * const ustats)
  96. {
  97. DEBUG_PRINT_L1("%s\t%7d\t%7.0f\t%7.0f\n",
  98. ustats->name, ustats->count,
  99. (float)ustats->total / (float)ustats->count,
  100. (float)ustats->bytes / (float)ustats->count);
  101. }
  102. static void print_stats(void)
  103. {
  104. DEBUG_PRINT_L1("\nSyscall\tCall\tAvgTime\tAvgSize\n"
  105. "\tCount\t(ticks)\t(bytes)\n"
  106. "-------------------------------\n");
  107. print_ustats(&read_stats);
  108. print_ustats(&pread_stats);
  109. print_ustats(&write_stats);
  110. print_ustats(&pwrite_stats);
  111. print_ustats(&seek_stats);
  112. }
  113. static int build_memory_map(void)
  114. {
  115. char line[256];
  116. FILE *fp;
  117. int i;
  118. range_count = 0;
  119. fp = fopen("/proc/iomem", "r");
  120. if (!fp) {
  121. fprintf(stderr, "/proc/iomem: error %d: %s\n",
  122. errno, strerror(errno));
  123. return -errno;
  124. }
  125. while (fgets(line, sizeof(line), fp) != 0) {
  126. if (strstr(line, system_ram_str)) {
  127. char *dash, *end_ptr;
  128. /* Given a line like this:
  129. * d0400000-10ffaffff : System RAM
  130. * replace the "-" with a space
  131. */
  132. dash = strstr(line, "-");
  133. dash[0] = 0x20;
  134. start_addr[range_count] = strtoull(line, &end_ptr, 16);
  135. end_addr[range_count] = strtoull(end_ptr, NULL, 16);
  136. range_count++;
  137. }
  138. }
  139. fclose(fp);
  140. DEBUG_PRINT_L1("RAM Ranges\n");
  141. for (i = 0; i < range_count; i++)
  142. DEBUG_PRINT_L1("\trange %d: 0x%llx\t- 0x%llx\n",
  143. i, start_addr[i], end_addr[i]);
  144. if (range_count == 0) {
  145. fprintf(stderr, "No valid address ranges found. Error.\n");
  146. return -1;
  147. }
  148. return 0;
  149. }
  150. static int read_adi(int fd, unsigned char *buf, int buf_sz)
  151. {
  152. int ret, bytes_read = 0;
  153. long start, end, elapsed_time = 0;
  154. do {
  155. RDTICK(start);
  156. ret = read(fd, buf + bytes_read, buf_sz - bytes_read);
  157. RDTICK(end);
  158. if (ret < 0)
  159. return -errno;
  160. elapsed_time += end - start;
  161. update_stats(&read_stats, elapsed_time, buf_sz);
  162. bytes_read += ret;
  163. } while (bytes_read < buf_sz);
  164. DEBUG_PRINT_T("\tread elapsed timed = %ld\n", elapsed_time);
  165. DEBUG_PRINT_L3("\tRead %d bytes\n", bytes_read);
  166. return bytes_read;
  167. }
  168. static int pread_adi(int fd, unsigned char *buf,
  169. int buf_sz, unsigned long offset)
  170. {
  171. int ret, i, bytes_read = 0;
  172. unsigned long cur_offset;
  173. long start, end, elapsed_time = 0;
  174. cur_offset = offset;
  175. do {
  176. RDTICK(start);
  177. ret = pread(fd, buf + bytes_read, buf_sz - bytes_read,
  178. cur_offset);
  179. RDTICK(end);
  180. if (ret < 0)
  181. return -errno;
  182. elapsed_time += end - start;
  183. update_stats(&pread_stats, elapsed_time, buf_sz);
  184. bytes_read += ret;
  185. cur_offset += ret;
  186. } while (bytes_read < buf_sz);
  187. DEBUG_PRINT_T("\tpread elapsed timed = %ld\n", elapsed_time);
  188. DEBUG_PRINT_L3("\tRead %d bytes starting at offset 0x%lx\n",
  189. bytes_read, offset);
  190. for (i = 0; i < bytes_read; i++)
  191. DEBUG_PRINT_L4("\t\t0x%lx\t%d\n", offset + i, buf[i]);
  192. return bytes_read;
  193. }
  194. static int write_adi(int fd, const unsigned char * const buf, int buf_sz)
  195. {
  196. int ret, bytes_written = 0;
  197. long start, end, elapsed_time = 0;
  198. do {
  199. RDTICK(start);
  200. ret = write(fd, buf + bytes_written, buf_sz - bytes_written);
  201. RDTICK(end);
  202. if (ret < 0)
  203. return -errno;
  204. elapsed_time += (end - start);
  205. update_stats(&write_stats, elapsed_time, buf_sz);
  206. bytes_written += ret;
  207. } while (bytes_written < buf_sz);
  208. DEBUG_PRINT_T("\twrite elapsed timed = %ld\n", elapsed_time);
  209. DEBUG_PRINT_L3("\tWrote %d of %d bytes\n", bytes_written, buf_sz);
  210. return bytes_written;
  211. }
  212. static int pwrite_adi(int fd, const unsigned char * const buf,
  213. int buf_sz, unsigned long offset)
  214. {
  215. int ret, bytes_written = 0;
  216. unsigned long cur_offset;
  217. long start, end, elapsed_time = 0;
  218. cur_offset = offset;
  219. do {
  220. RDTICK(start);
  221. ret = pwrite(fd, buf + bytes_written,
  222. buf_sz - bytes_written, cur_offset);
  223. RDTICK(end);
  224. if (ret < 0) {
  225. fprintf(stderr, "pwrite(): error %d: %s\n",
  226. errno, strerror(errno));
  227. return -errno;
  228. }
  229. elapsed_time += (end - start);
  230. update_stats(&pwrite_stats, elapsed_time, buf_sz);
  231. bytes_written += ret;
  232. cur_offset += ret;
  233. } while (bytes_written < buf_sz);
  234. DEBUG_PRINT_T("\tpwrite elapsed timed = %ld\n", elapsed_time);
  235. DEBUG_PRINT_L3("\tWrote %d of %d bytes starting at address 0x%lx\n",
  236. bytes_written, buf_sz, offset);
  237. return bytes_written;
  238. }
  239. static off_t seek_adi(int fd, off_t offset, int whence)
  240. {
  241. long start, end;
  242. off_t ret;
  243. RDTICK(start);
  244. ret = lseek(fd, offset, whence);
  245. RDTICK(end);
  246. DEBUG_PRINT_L2("\tlseek ret = 0x%llx\n", ret);
  247. if (ret < 0)
  248. goto out;
  249. DEBUG_PRINT_T("\tlseek elapsed timed = %ld\n", end - start);
  250. update_stats(&seek_stats, end - start, 0);
  251. out:
  252. (void)lseek(fd, 0, SEEK_END);
  253. return ret;
  254. }
  255. static int test0_prpw_aligned_1byte(int fd)
  256. {
  257. /* somewhat arbitrarily chosen address */
  258. unsigned long paddr =
  259. (end_addr[range_count - 1] - 0x1000) & ~(ADI_BLKSZ - 1);
  260. unsigned char version[1], expected_version;
  261. loff_t offset;
  262. int ret;
  263. version[0] = random_version();
  264. expected_version = version[0];
  265. offset = paddr / ADI_BLKSZ;
  266. ret = pwrite_adi(fd, version, sizeof(version), offset);
  267. if (ret != sizeof(version))
  268. TEST_STEP_FAILURE(ret);
  269. ret = pread_adi(fd, version, sizeof(version), offset);
  270. if (ret != sizeof(version))
  271. TEST_STEP_FAILURE(ret);
  272. if (expected_version != version[0]) {
  273. DEBUG_PRINT_L2("\tExpected version %d but read version %d\n",
  274. expected_version, version[0]);
  275. TEST_STEP_FAILURE(-expected_version);
  276. }
  277. ret = 0;
  278. out:
  279. RETURN_FROM_TEST(ret);
  280. }
  281. #define TEST1_VERSION_SZ 4096
  282. static int test1_prpw_aligned_4096bytes(int fd)
  283. {
  284. /* somewhat arbitrarily chosen address */
  285. unsigned long paddr =
  286. (end_addr[range_count - 1] - 0x6000) & ~(ADI_BLKSZ - 1);
  287. unsigned char version[TEST1_VERSION_SZ],
  288. expected_version[TEST1_VERSION_SZ];
  289. loff_t offset;
  290. int ret, i;
  291. for (i = 0; i < TEST1_VERSION_SZ; i++) {
  292. version[i] = random_version();
  293. expected_version[i] = version[i];
  294. }
  295. offset = paddr / ADI_BLKSZ;
  296. ret = pwrite_adi(fd, version, sizeof(version), offset);
  297. if (ret != sizeof(version))
  298. TEST_STEP_FAILURE(ret);
  299. ret = pread_adi(fd, version, sizeof(version), offset);
  300. if (ret != sizeof(version))
  301. TEST_STEP_FAILURE(ret);
  302. for (i = 0; i < TEST1_VERSION_SZ; i++) {
  303. if (expected_version[i] != version[i]) {
  304. DEBUG_PRINT_L2(
  305. "\tExpected version %d but read version %d\n",
  306. expected_version, version[0]);
  307. TEST_STEP_FAILURE(-expected_version[i]);
  308. }
  309. }
  310. ret = 0;
  311. out:
  312. RETURN_FROM_TEST(ret);
  313. }
  314. #define TEST2_VERSION_SZ 10327
  315. static int test2_prpw_aligned_10327bytes(int fd)
  316. {
  317. /* somewhat arbitrarily chosen address */
  318. unsigned long paddr =
  319. (start_addr[0] + 0x6000) & ~(ADI_BLKSZ - 1);
  320. unsigned char version[TEST2_VERSION_SZ],
  321. expected_version[TEST2_VERSION_SZ];
  322. loff_t offset;
  323. int ret, i;
  324. for (i = 0; i < TEST2_VERSION_SZ; i++) {
  325. version[i] = random_version();
  326. expected_version[i] = version[i];
  327. }
  328. offset = paddr / ADI_BLKSZ;
  329. ret = pwrite_adi(fd, version, sizeof(version), offset);
  330. if (ret != sizeof(version))
  331. TEST_STEP_FAILURE(ret);
  332. ret = pread_adi(fd, version, sizeof(version), offset);
  333. if (ret != sizeof(version))
  334. TEST_STEP_FAILURE(ret);
  335. for (i = 0; i < TEST2_VERSION_SZ; i++) {
  336. if (expected_version[i] != version[i]) {
  337. DEBUG_PRINT_L2(
  338. "\tExpected version %d but read version %d\n",
  339. expected_version, version[0]);
  340. TEST_STEP_FAILURE(-expected_version[i]);
  341. }
  342. }
  343. ret = 0;
  344. out:
  345. RETURN_FROM_TEST(ret);
  346. }
  347. #define TEST3_VERSION_SZ 12541
  348. static int test3_prpw_unaligned_12541bytes(int fd)
  349. {
  350. /* somewhat arbitrarily chosen address */
  351. unsigned long paddr =
  352. ((start_addr[0] + 0xC000) & ~(ADI_BLKSZ - 1)) + 17;
  353. unsigned char version[TEST3_VERSION_SZ],
  354. expected_version[TEST3_VERSION_SZ];
  355. loff_t offset;
  356. int ret, i;
  357. for (i = 0; i < TEST3_VERSION_SZ; i++) {
  358. version[i] = random_version();
  359. expected_version[i] = version[i];
  360. }
  361. offset = paddr / ADI_BLKSZ;
  362. ret = pwrite_adi(fd, version, sizeof(version), offset);
  363. if (ret != sizeof(version))
  364. TEST_STEP_FAILURE(ret);
  365. ret = pread_adi(fd, version, sizeof(version), offset);
  366. if (ret != sizeof(version))
  367. TEST_STEP_FAILURE(ret);
  368. for (i = 0; i < TEST3_VERSION_SZ; i++) {
  369. if (expected_version[i] != version[i]) {
  370. DEBUG_PRINT_L2(
  371. "\tExpected version %d but read version %d\n",
  372. expected_version, version[0]);
  373. TEST_STEP_FAILURE(-expected_version[i]);
  374. }
  375. }
  376. ret = 0;
  377. out:
  378. RETURN_FROM_TEST(ret);
  379. }
  380. static int test4_lseek(int fd)
  381. {
  382. #define OFFSET_ADD (0x100)
  383. #define OFFSET_SUBTRACT (0xFFFFFFF000000000)
  384. off_t offset_out, offset_in;
  385. int ret;
  386. offset_in = 0x123456789abcdef0;
  387. offset_out = seek_adi(fd, offset_in, SEEK_SET);
  388. if (offset_out != offset_in) {
  389. ret = -1;
  390. TEST_STEP_FAILURE(ret);
  391. }
  392. /* seek to the current offset. this should return EINVAL */
  393. offset_out = seek_adi(fd, offset_in, SEEK_SET);
  394. if (offset_out < 0 && errno == EINVAL)
  395. DEBUG_PRINT_L2(
  396. "\tSEEK_SET failed as designed. Not an error\n");
  397. else {
  398. ret = -2;
  399. TEST_STEP_FAILURE(ret);
  400. }
  401. offset_out = seek_adi(fd, 0, SEEK_CUR);
  402. if (offset_out != offset_in) {
  403. ret = -3;
  404. TEST_STEP_FAILURE(ret);
  405. }
  406. offset_out = seek_adi(fd, OFFSET_ADD, SEEK_CUR);
  407. if (offset_out != (offset_in + OFFSET_ADD)) {
  408. ret = -4;
  409. TEST_STEP_FAILURE(ret);
  410. }
  411. offset_out = seek_adi(fd, OFFSET_SUBTRACT, SEEK_CUR);
  412. if (offset_out != (offset_in + OFFSET_ADD + OFFSET_SUBTRACT)) {
  413. ret = -5;
  414. TEST_STEP_FAILURE(ret);
  415. }
  416. ret = 0;
  417. out:
  418. RETURN_FROM_TEST(ret);
  419. }
  420. static int test5_rw_aligned_1byte(int fd)
  421. {
  422. /* somewhat arbitrarily chosen address */
  423. unsigned long paddr =
  424. (end_addr[range_count - 1] - 0xF000) & ~(ADI_BLKSZ - 1);
  425. unsigned char version, expected_version;
  426. loff_t offset;
  427. off_t oret;
  428. int ret;
  429. offset = paddr / ADI_BLKSZ;
  430. version = expected_version = random_version();
  431. oret = seek_adi(fd, offset, SEEK_SET);
  432. if (oret != offset) {
  433. ret = -1;
  434. TEST_STEP_FAILURE(ret);
  435. }
  436. ret = write_adi(fd, &version, sizeof(version));
  437. if (ret != sizeof(version))
  438. TEST_STEP_FAILURE(ret);
  439. oret = seek_adi(fd, offset, SEEK_SET);
  440. if (oret != offset) {
  441. ret = -1;
  442. TEST_STEP_FAILURE(ret);
  443. }
  444. ret = read_adi(fd, &version, sizeof(version));
  445. if (ret != sizeof(version))
  446. TEST_STEP_FAILURE(ret);
  447. if (expected_version != version) {
  448. DEBUG_PRINT_L2("\tExpected version %d but read version %d\n",
  449. expected_version, version);
  450. TEST_STEP_FAILURE(-expected_version);
  451. }
  452. ret = 0;
  453. out:
  454. RETURN_FROM_TEST(ret);
  455. }
  456. #define TEST6_VERSION_SZ 9434
  457. static int test6_rw_aligned_9434bytes(int fd)
  458. {
  459. /* somewhat arbitrarily chosen address */
  460. unsigned long paddr =
  461. (end_addr[range_count - 1] - 0x5F000) & ~(ADI_BLKSZ - 1);
  462. unsigned char version[TEST6_VERSION_SZ],
  463. expected_version[TEST6_VERSION_SZ];
  464. loff_t offset;
  465. off_t oret;
  466. int ret, i;
  467. offset = paddr / ADI_BLKSZ;
  468. for (i = 0; i < TEST6_VERSION_SZ; i++)
  469. version[i] = expected_version[i] = random_version();
  470. oret = seek_adi(fd, offset, SEEK_SET);
  471. if (oret != offset) {
  472. ret = -1;
  473. TEST_STEP_FAILURE(ret);
  474. }
  475. ret = write_adi(fd, version, sizeof(version));
  476. if (ret != sizeof(version))
  477. TEST_STEP_FAILURE(ret);
  478. memset(version, 0, TEST6_VERSION_SZ);
  479. oret = seek_adi(fd, offset, SEEK_SET);
  480. if (oret != offset) {
  481. ret = -1;
  482. TEST_STEP_FAILURE(ret);
  483. }
  484. ret = read_adi(fd, version, sizeof(version));
  485. if (ret != sizeof(version))
  486. TEST_STEP_FAILURE(ret);
  487. for (i = 0; i < TEST6_VERSION_SZ; i++) {
  488. if (expected_version[i] != version[i]) {
  489. DEBUG_PRINT_L2(
  490. "\tExpected version %d but read version %d\n",
  491. expected_version[i], version[i]);
  492. TEST_STEP_FAILURE(-expected_version[i]);
  493. }
  494. }
  495. ret = 0;
  496. out:
  497. RETURN_FROM_TEST(ret);
  498. }
  499. #define TEST7_VERSION_SZ 14963
  500. static int test7_rw_aligned_14963bytes(int fd)
  501. {
  502. /* somewhat arbitrarily chosen address */
  503. unsigned long paddr =
  504. ((start_addr[range_count - 1] + 0xF000) & ~(ADI_BLKSZ - 1)) + 39;
  505. unsigned char version[TEST7_VERSION_SZ],
  506. expected_version[TEST7_VERSION_SZ];
  507. loff_t offset;
  508. off_t oret;
  509. int ret, i;
  510. offset = paddr / ADI_BLKSZ;
  511. for (i = 0; i < TEST7_VERSION_SZ; i++) {
  512. version[i] = random_version();
  513. expected_version[i] = version[i];
  514. }
  515. oret = seek_adi(fd, offset, SEEK_SET);
  516. if (oret != offset) {
  517. ret = -1;
  518. TEST_STEP_FAILURE(ret);
  519. }
  520. ret = write_adi(fd, version, sizeof(version));
  521. if (ret != sizeof(version))
  522. TEST_STEP_FAILURE(ret);
  523. memset(version, 0, TEST7_VERSION_SZ);
  524. oret = seek_adi(fd, offset, SEEK_SET);
  525. if (oret != offset) {
  526. ret = -1;
  527. TEST_STEP_FAILURE(ret);
  528. }
  529. ret = read_adi(fd, version, sizeof(version));
  530. if (ret != sizeof(version))
  531. TEST_STEP_FAILURE(ret);
  532. for (i = 0; i < TEST7_VERSION_SZ; i++) {
  533. if (expected_version[i] != version[i]) {
  534. DEBUG_PRINT_L2(
  535. "\tExpected version %d but read version %d\n",
  536. expected_version[i], version[i]);
  537. TEST_STEP_FAILURE(-expected_version[i]);
  538. }
  539. paddr += ADI_BLKSZ;
  540. }
  541. ret = 0;
  542. out:
  543. RETURN_FROM_TEST(ret);
  544. }
  545. static int (*tests[])(int fd) = {
  546. test0_prpw_aligned_1byte,
  547. test1_prpw_aligned_4096bytes,
  548. test2_prpw_aligned_10327bytes,
  549. test3_prpw_unaligned_12541bytes,
  550. test4_lseek,
  551. test5_rw_aligned_1byte,
  552. test6_rw_aligned_9434bytes,
  553. test7_rw_aligned_14963bytes,
  554. };
  555. #define TEST_COUNT ARRAY_SIZE(tests)
  556. int main(int argc, char *argv[])
  557. {
  558. int fd, ret, test;
  559. ret = build_memory_map();
  560. if (ret < 0)
  561. return ret;
  562. fd = open("/dev/adi", O_RDWR);
  563. if (fd < 0) {
  564. fprintf(stderr, "open: error %d: %s\n",
  565. errno, strerror(errno));
  566. return -errno;
  567. }
  568. for (test = 0; test < TEST_COUNT; test++) {
  569. DEBUG_PRINT_L1("Running test #%d\n", test);
  570. ret = (*tests[test])(fd);
  571. if (ret != 0)
  572. ksft_test_result_fail("Test #%d failed: error %d\n",
  573. test, ret);
  574. else
  575. ksft_test_result_pass("Test #%d passed\n", test);
  576. }
  577. print_stats();
  578. close(fd);
  579. if (ksft_get_fail_cnt() > 0)
  580. ksft_exit_fail();
  581. else
  582. ksft_exit_pass();
  583. /* it's impossible to get here, but the compiler throws a warning
  584. * about control reaching the end of non-void function. bah.
  585. */
  586. return 0;
  587. }