vfs: fix unregister removing top level VFS instead of nested

Credits @neoniousTR.

Fixes https://github.com/espressif/esp-idf/pull/2770
This commit is contained in:
Ivan Grokhotkov
2018-12-06 19:30:05 +08:00
parent a36d714d1a
commit 61beb16225
2 changed files with 43 additions and 1 deletions

View File

@@ -206,6 +206,46 @@ TEST_CASE("vfs parses paths correctly", "[vfs]")
TEST_ESP_OK( esp_vfs_unregister("") );
}
TEST_CASE("vfs unregisters correct nested mount point", "[vfs]")
{
dummy_vfs_t inst_foobar = {
.match_path = "/file",
.called = false
};
esp_vfs_t desc_foobar = DUMMY_VFS();
TEST_ESP_OK( esp_vfs_register("/foo/bar", &desc_foobar, &inst_foobar) );
dummy_vfs_t inst_foo = {
.match_path = "/bar/file",
.called = false
};
esp_vfs_t desc_foo = DUMMY_VFS();
TEST_ESP_OK( esp_vfs_register("/foo", &desc_foo, &inst_foo) );
/* basic operation */
test_opened(&inst_foobar, "/foo/bar/file");
test_not_called(&inst_foo, "/foo/bar/file");
/* this should not match anything */
TEST_ESP_ERR(ESP_ERR_INVALID_STATE, esp_vfs_unregister("/foo/b"));
/* unregister "/foo" and check that we haven't unregistered "/foo/bar" */
TEST_ESP_OK( esp_vfs_unregister("/foo") );
test_not_called(&inst_foo, "/foo/bar/file");
test_opened(&inst_foobar, "/foo/bar/file");
/* repeat the above, with the reverse order of registration */
TEST_ESP_OK( esp_vfs_unregister("/foo/bar") );
TEST_ESP_OK( esp_vfs_register("/foo", &desc_foo, &inst_foo) );
TEST_ESP_OK( esp_vfs_register("/foo/bar", &desc_foobar, &inst_foobar) );
test_opened(&inst_foobar, "/foo/bar/file");
test_not_called(&inst_foo, "/foo/bar/file");
TEST_ESP_OK( esp_vfs_unregister("/foo") );
test_not_called(&inst_foo, "/foo/bar/file");
test_opened(&inst_foobar, "/foo/bar/file");
TEST_ESP_OK( esp_vfs_unregister("/foo/bar") );
}
void test_vfs_register(const char* prefix, bool expect_success, int line)
{