@@ -150,3 +150,30 @@ ZTEST(posix_fs_dir_test, test_fs_readdir_threadsafe)
150150 zassert_true (test_mkdir () == TC_PASS );
151151 zassert_true (test_lsdir (TEST_DIR , true) == TC_PASS );
152152}
153+
154+ /**
155+ * @brief Test for POSIX rmdir API
156+ *
157+ * @details Test creates a new directory through POSIX
158+ * mkdir API and remove directory using rmdir.
159+ */
160+ ZTEST (posix_fs_dir_test , test_fs_rmdir )
161+ {
162+ #define IRWXG 0070
163+ /* Create and remove empty directory */
164+ zassert_ok (mkdir (TEST_DIR , IRWXG ), "Error creating dir: %d" , errno );
165+ zassert_ok (rmdir (TEST_DIR ), "Error removing dir: %d\n" , errno );
166+
167+ /* Create directory and open a file in the directory
168+ * now removing the directory will fail, test will
169+ * fail in removal of non empty directory
170+ */
171+ zassert_ok (mkdir (TEST_DIR , IRWXG ), "Error creating dir: %d" , errno );
172+ zassert_not_equal (open (TEST_DIR_FILE , O_CREAT | O_RDWR ), -1 ,
173+ "Error creating file: %d" , errno );
174+ zassert_not_ok (rmdir (TEST_DIR ), "Error Non empty dir removed" );
175+ zassert_not_ok (rmdir ("" ), "Error Invalid path removed" );
176+ zassert_not_ok (rmdir (NULL ), "Error Invalid path removed" );
177+ zassert_not_ok (rmdir ("TEST_DIR." ), "Error Invalid path removed" );
178+ zassert_not_ok (rmdir (TEST_FILE ), "Error file removed" );
179+ }
0 commit comments