tmpfs.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2006-2019, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024-5-20 Zhujiale the first version
  9. */
  10. #include <rtthread.h>
  11. #include <stdlib.h>
  12. #include <errno.h>
  13. #include <fcntl.h>
  14. #include <unistd.h>
  15. #include <msh.h>
  16. #include "utest.h"
  17. #include "utest_assert.h"
  18. #include "common.h"
  19. void run_copy()
  20. {
  21. int ret = 0;
  22. ret = msh_exec("cd /tmp", 7);
  23. if (ret != 0)
  24. {
  25. LOG_E("errno=%d, ret=%d\n", errno, ret);
  26. LOG_E("cd /tmp error");
  27. uassert_false(1);
  28. }
  29. uassert_true(1);
  30. ret = msh_exec("touch test", 10);
  31. if (ret != 0)
  32. {
  33. LOG_E("errno=%d, ret=%d\n", errno, ret);
  34. LOG_E("touch test error");
  35. uassert_false(1);
  36. }
  37. uassert_true(1);
  38. ret = msh_exec("echo this_is_a_test_file test", 29);
  39. if (ret != 0)
  40. {
  41. LOG_E("errno=%d, ret=%d\n", errno, ret);
  42. LOG_E("echo this_is_a_test_file test error");
  43. uassert_false(1);
  44. }
  45. uassert_true(1);
  46. ret = msh_exec("cp test test1", 13);
  47. if (ret != 0)
  48. {
  49. LOG_E("errno=%d, ret=%d\n", errno, ret);
  50. LOG_E("cp test test1 error");
  51. uassert_false(1);
  52. }
  53. uassert_true(1);
  54. }
  55. static void run_long_name_reject(void)
  56. {
  57. static const char long_name[] =
  58. "/tmp/abcdefghijklmnopqrstuvwxyz1234567890";
  59. int fd;
  60. errno = 0;
  61. fd = open(long_name, O_CREAT | O_RDWR, 0);
  62. uassert_int_equal(fd, -1);
  63. uassert_int_equal(errno, -ENAMETOOLONG);
  64. }
  65. static rt_err_t utest_tc_init(void)
  66. {
  67. return RT_EOK;
  68. }
  69. static rt_err_t utest_tc_cleanup(void)
  70. {
  71. return RT_EOK;
  72. }
  73. static void testcase(void)
  74. {
  75. UTEST_UNIT_RUN(run_copy);
  76. UTEST_UNIT_RUN(run_long_name_reject);
  77. }
  78. UTEST_TC_EXPORT(testcase, "testcase.tfs.tmpfs", utest_tc_init, utest_tc_cleanup, 10);