adi-test.c 16 KB

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