-
Notifications
You must be signed in to change notification settings - Fork 3k
littlefs: Fixed issue with cleanup in mount function on error #7851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
199 changes: 199 additions & 0 deletions
199
features/filesystem/littlefs/TESTS/filesystem_integration/format/main.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
/* mbed Microcontroller Library | ||
* Copyright (c) 2017 ARM Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include "mbed.h" | ||
#include "greentea-client/test_env.h" | ||
#include "unity.h" | ||
#include "utest.h" | ||
#include <stdlib.h> | ||
#include <errno.h> | ||
|
||
using namespace utest::v1; | ||
|
||
// test configuration | ||
#ifndef MBED_TEST_FILESYSTEM | ||
#define MBED_TEST_FILESYSTEM LittleFileSystem | ||
#endif | ||
|
||
#ifndef MBED_TEST_FILESYSTEM_DECL | ||
#define MBED_TEST_FILESYSTEM_DECL MBED_TEST_FILESYSTEM fs("fs") | ||
#endif | ||
|
||
#ifndef MBED_TEST_BLOCKDEVICE | ||
#error [NOT_SUPPORTED] Non-volatile block device required | ||
#endif | ||
|
||
#ifndef MBED_TEST_BLOCKDEVICE_DECL | ||
#define MBED_TEST_BLOCKDEVICE_DECL MBED_TEST_BLOCKDEVICE bd | ||
#endif | ||
|
||
#ifndef MBED_TEST_FILES | ||
#define MBED_TEST_FILES 4 | ||
#endif | ||
|
||
#ifndef MBED_TEST_DIRS | ||
#define MBED_TEST_DIRS 4 | ||
#endif | ||
|
||
#ifndef MBED_TEST_BUFFER | ||
#define MBED_TEST_BUFFER 8192 | ||
#endif | ||
|
||
#ifndef MBED_TEST_TIMEOUT | ||
#define MBED_TEST_TIMEOUT 480 | ||
#endif | ||
|
||
|
||
// declarations | ||
#define STRINGIZE(x) STRINGIZE2(x) | ||
#define STRINGIZE2(x) #x | ||
#define INCLUDE(x) STRINGIZE(x.h) | ||
|
||
#include INCLUDE(MBED_TEST_FILESYSTEM) | ||
#include INCLUDE(MBED_TEST_BLOCKDEVICE) | ||
|
||
MBED_TEST_FILESYSTEM_DECL; | ||
MBED_TEST_BLOCKDEVICE_DECL; | ||
|
||
Dir dir[MBED_TEST_DIRS]; | ||
File file[MBED_TEST_FILES]; | ||
DIR *dd[MBED_TEST_DIRS]; | ||
FILE *fd[MBED_TEST_FILES]; | ||
struct dirent ent; | ||
struct dirent *ed; | ||
size_t size; | ||
uint8_t buffer[MBED_TEST_BUFFER]; | ||
uint8_t rbuffer[MBED_TEST_BUFFER]; | ||
uint8_t wbuffer[MBED_TEST_BUFFER]; | ||
|
||
|
||
// tests for integration level format operations | ||
|
||
void test_format() | ||
{ | ||
int res = bd.init(); | ||
TEST_ASSERT_EQUAL(0, res); | ||
|
||
{ | ||
res = MBED_TEST_FILESYSTEM::format(&bd); | ||
TEST_ASSERT_EQUAL(0, res); | ||
} | ||
|
||
res = bd.deinit(); | ||
TEST_ASSERT_EQUAL(0, res); | ||
} | ||
|
||
void test_mount() | ||
{ | ||
int res = bd.init(); | ||
TEST_ASSERT_EQUAL(0, res); | ||
|
||
{ | ||
res = fs.mount(&bd); | ||
TEST_ASSERT_EQUAL(0, res); | ||
res = fs.unmount(); | ||
TEST_ASSERT_EQUAL(0, res); | ||
} | ||
|
||
res = bd.deinit(); | ||
TEST_ASSERT_EQUAL(0, res); | ||
} | ||
|
||
void test_bad_mount() | ||
{ | ||
int res = bd.init(); | ||
TEST_ASSERT_EQUAL(0, res); | ||
|
||
{ | ||
res = bd.erase(0, 2*bd.get_erase_size()); | ||
TEST_ASSERT_EQUAL(0, res); | ||
memset(buffer, 0, bd.get_program_size()); | ||
for (int i = 0; i < 2*bd.get_erase_size(); i += bd.get_program_size()) { | ||
res = bd.program(buffer, i, bd.get_program_size()); | ||
TEST_ASSERT_EQUAL(0, res); | ||
} | ||
} | ||
|
||
{ | ||
res = fs.mount(&bd); | ||
TEST_ASSERT_NOT_EQUAL(0, res); | ||
} | ||
|
||
res = bd.deinit(); | ||
TEST_ASSERT_EQUAL(0, res); | ||
} | ||
|
||
void test_bad_mount_then_reformat() | ||
{ | ||
int res = bd.init(); | ||
TEST_ASSERT_EQUAL(0, res); | ||
|
||
{ | ||
res = fs.mount(&bd); | ||
TEST_ASSERT_NOT_EQUAL(0, res); | ||
|
||
res = fs.reformat(&bd); | ||
TEST_ASSERT_EQUAL(0, res); | ||
|
||
res = fs.unmount(); | ||
TEST_ASSERT_EQUAL(0, res); | ||
} | ||
|
||
res = bd.deinit(); | ||
TEST_ASSERT_EQUAL(0, res); | ||
} | ||
|
||
void test_good_mount_then_reformat() | ||
{ | ||
int res = bd.init(); | ||
TEST_ASSERT_EQUAL(0, res); | ||
|
||
{ | ||
res = fs.mount(&bd); | ||
TEST_ASSERT_EQUAL(0, res); | ||
|
||
res = fs.reformat(&bd); | ||
TEST_ASSERT_EQUAL(0, res); | ||
|
||
res = fs.unmount(); | ||
TEST_ASSERT_EQUAL(0, res); | ||
} | ||
|
||
res = bd.deinit(); | ||
TEST_ASSERT_EQUAL(0, res); | ||
} | ||
|
||
|
||
// test setup | ||
utest::v1::status_t test_setup(const size_t number_of_cases) | ||
{ | ||
GREENTEA_SETUP(MBED_TEST_TIMEOUT, "default_auto"); | ||
return verbose_test_setup_handler(number_of_cases); | ||
} | ||
|
||
Case cases[] = { | ||
Case("Test format", test_format), | ||
Case("Test mount", test_mount), | ||
Case("Test bad mount", test_bad_mount), | ||
Case("Test bad mount than reformat", test_bad_mount_then_reformat), | ||
Case("Test good mount than reformat", test_good_mount_then_reformat), | ||
}; | ||
|
||
Specification specification(test_setup, cases); | ||
|
||
int main() | ||
{ | ||
return !Harness::run(specification); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a nit: !res check is not really needed hereToo late :-)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I just kept it for consistency. That way if any code is added between the declaration of res and this line, it won't break anything.
The compiler will optimize it out anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Famous last words