Import Mbed OS hard-float snapshot
This commit is contained in:
21
storage/filesystem/littlefs/tests/TESTS/util/Makefile
Normal file
21
storage/filesystem/littlefs/tests/TESTS/util/Makefile
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
all: test_dirs test_files test_seek test_parallel
|
||||
|
||||
test_%: ../../littlefs/tests/test_%.sh
|
||||
cp $< $(notdir $<)
|
||||
sed -i -e 's/tests\//.\//' -e 's/echo/.\/echo.py/' $(notdir $<)
|
||||
|
||||
./clean.sh
|
||||
ln -f -s replacements_mbed.yml replacements.yml
|
||||
./$(notdir $<)
|
||||
mkdir -p ../filesystem/$(patsubst test_%,%,$@)
|
||||
cp main.cpp ../filesystem/$(patsubst test_%,%,$@)/main.cpp
|
||||
|
||||
./clean.sh
|
||||
ln -f -s replacements_retarget.yml replacements.yml
|
||||
./$(notdir $<)
|
||||
mkdir -p ../filesystem_retarget/$(patsubst test_%,%,$@)
|
||||
cp main.cpp ../filesystem_retarget/$(patsubst test_%,%,$@)/main.cpp
|
||||
|
||||
clean:
|
||||
./clean.sh
|
||||
4
storage/filesystem/littlefs/tests/TESTS/util/clean.sh
Normal file
4
storage/filesystem/littlefs/tests/TESTS/util/clean.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
rm -f main.cpp
|
||||
rm -f template_all_names.txt
|
||||
34
storage/filesystem/littlefs/tests/TESTS/util/echo.py
Normal file
34
storage/filesystem/littlefs/tests/TESTS/util/echo.py
Normal file
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import re
|
||||
import sys
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
def main(*args):
|
||||
desc = ' '.join(args).strip('-= ')
|
||||
name = 'test_' + desc.lower().replace(' ', '_').replace('-', '_')
|
||||
|
||||
exists = os.path.isfile('template_all_names.txt')
|
||||
|
||||
with open('template_all_names.txt', 'a') as file:
|
||||
file.write(name + '\n')
|
||||
file.write(desc + '\n')
|
||||
|
||||
with open('template_unit.fmt') as file:
|
||||
template = file.read()
|
||||
|
||||
template_header, template_footer = template.split('{test}')
|
||||
|
||||
if exists:
|
||||
with open('main.cpp', 'a') as file:
|
||||
file.write(template_footer.format(
|
||||
test_name=name))
|
||||
|
||||
if name != 'test_results':
|
||||
with open('main.cpp', 'a') as file:
|
||||
file.write(template_header.format(
|
||||
test_name=name))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(*sys.argv[1:])
|
||||
@@ -0,0 +1,33 @@
|
||||
- ['lfs_format\(&lfs, &cfg\)', 'MBED_TEST_FILESYSTEM::format(&bd)']
|
||||
- ['lfs_mount\(&lfs, &cfg\)', 'fs.mount(&bd)']
|
||||
- ['lfs_unmount\(&lfs\)', 'fs.unmount()']
|
||||
- ['lfs_mkdir\(&lfs, (.*)\)', 'fs.mkdir(\1, 0777)']
|
||||
- ['lfs_remove\(&lfs, (.*)\)', 'fs.remove(\1)']
|
||||
- ['lfs_rename\(&lfs, (.*), ?(.*)\)', 'fs.rename(\1, \2)']
|
||||
|
||||
- ['lfs_dir_open\(&lfs, &dir\[(.*)\], ?(.*)\)', 'dir[\1].open(&fs, \2)']
|
||||
- ['lfs_dir_close\(&lfs, &dir\[(.*)\]\)', 'dir[\1].close()']
|
||||
- ['lfs_dir_read\(&lfs, &dir\[(.*)\], &info\)', 'dir[\1].read(&ent)']
|
||||
- ['lfs_dir_seek\(&lfs, &dir\[(.*)\], ?(.*)\).*;', 'dir[\1].seek(\2);'] # no dir errors
|
||||
- ['lfs_dir_rewind\(&lfs, &dir\[(.*)\]\).*;', 'dir[\1].rewind();'] # no dir errors
|
||||
- ['lfs_dir_tell\(&lfs, &dir\[(.*)\]\)', 'dir[\1].tell()']
|
||||
|
||||
- ['lfs_file_open\(&lfs, &file\[(.*)\], ?(.*)\)', 'file[\1].open(&fs, \2)']
|
||||
- ['lfs_file_close\(&lfs, &file\[(.*)\]\)', 'file[\1].close()']
|
||||
- ['lfs_file_sync\(&lfs, &file\[(.*)\]\)', 'file[\1].sync()']
|
||||
- ['lfs_file_write\(&lfs, &file\[(.*)\], ?(.*), (.*)\)', 'file[\1].write(\2, \3)']
|
||||
- ['lfs_file_read\(&lfs, &file\[(.*)\], ?(.*), (.*)\)', 'file[\1].read(\2, \3)']
|
||||
- ['lfs_file_seek\(&lfs, &file\[(.*)\], ?(.*)\)', 'file[\1].seek(\2)']
|
||||
- ['lfs_file_tell\(&lfs, &file\[(.*)\]\)', 'file[\1].tell()']
|
||||
- ['lfs_file_rewind\(&lfs, &file\[(.*)\]\).*;', 'file[\1].rewind();'] # no errors
|
||||
- ['lfs_file_size\(&lfs, &file\[(.*)\]\)', 'file[\1].size()']
|
||||
|
||||
- ['LFS_TYPE_([A-Z]+)', 'DT_\1']
|
||||
- ['LFS_O_([A-Z]+)', 'O_\1']
|
||||
- ['LFS_SEEK_([A-Z]+)', 'SEEK_\1']
|
||||
- ['LFS_ERR_([A-Z]+)', '-E\1']
|
||||
- ['lfs_(s?)size_t', '\1size_t']
|
||||
- ['lfs_soff_t', 'off_t']
|
||||
- ['info\.name', 'ent.d_name']
|
||||
- ['info\.type', 'ent.d_type']
|
||||
- ['^.*info\.size.*$', ''] # dirent sizes not supported
|
||||
@@ -0,0 +1,37 @@
|
||||
- ['lfs_format\(&lfs, &cfg\)', 'MBED_TEST_FILESYSTEM::format(&bd)']
|
||||
- ['lfs_mount\(&lfs, &cfg\)', 'fs.mount(&bd)']
|
||||
- ['lfs_unmount\(&lfs\)', 'fs.unmount()']
|
||||
- ['lfs_mkdir\(&lfs, (.*)\)', 'mkdir("/fs/" \1, 0777)']
|
||||
- ['lfs_remove\(&lfs, (.*)\)', 'remove("/fs/" \1)']
|
||||
- ['lfs_rename\(&lfs, (.*), ?(.*)\)', 'rename("/fs/" \1, "/fs/" \2)']
|
||||
|
||||
- ['lfs_dir_open\(&lfs, &dir\[(.*)\], ?(.*)\)', '!((dd[\1] = opendir("/fs/" \2)) != NULL)']
|
||||
- ['lfs_dir_close\(&lfs, &dir\[(.*)\]\)', 'closedir(dd[\1])']
|
||||
- ['lfs_dir_read\(&lfs, &dir\[(.*)\], &info\)', '((ed = readdir(dd[\1])) != NULL)']
|
||||
- ['lfs_dir_seek\(&lfs, &dir\[(.*)\], ?(.*)\).*;', 'seekdir(dd[\1], \2);'] # no dir errors
|
||||
- ['lfs_dir_rewind\(&lfs, &dir\[(.*)\]\).*;', 'rewinddir(dd[\1]);'] # no dir errors
|
||||
- ['lfs_dir_tell\(&lfs, &dir\[(.*)\]\)', 'telldir(dd[\1])']
|
||||
|
||||
- ['lfs_file_open\(&lfs, &file\[(.*)\], ?(.*)\)', '!((fd[\1] = fopen("/fs/" \2)) != NULL)']
|
||||
- ['lfs_file_close\(&lfs, &file\[(.*)\]\)', 'fclose(fd[\1])']
|
||||
- ['lfs_file_sync\(&lfs, &file\[(.*)\]\)', 'fflush(fd[\1])']
|
||||
- ['lfs_file_write\(&lfs, &file\[(.*)\], ?(.*), (.*)\)', 'fwrite(\2, 1, \3, fd[\1])']
|
||||
- ['lfs_file_read\(&lfs, &file\[(.*)\], ?(.*), (.*)\)', 'fread(\2, 1, \3, fd[\1])']
|
||||
- ['lfs_file_tell\(&lfs, &file\[(.*)\]\)', 'ftell(fd[\1])']
|
||||
- ['lfs_file_rewind\(&lfs, &file\[(.*)\]\).*;', 'rewind(fd[\1]);'] # no errors
|
||||
|
||||
- ['LFS_TYPE_([A-Z]+)', 'DT_\1']
|
||||
- ['LFS_SEEK_([A-Z]+)', 'SEEK_\1']
|
||||
- ['LFS_ERR_([A-Z]+)', '-E\1']
|
||||
- ['lfs_(s?)size_t', '\1size_t']
|
||||
- ['lfs_soff_t', 'off_t']
|
||||
- ['info\.name', 'ed->d_name']
|
||||
- ['info\.type', 'ed->d_type']
|
||||
- ['^.*info\.size.*$', ''] # dirent sizes not supported
|
||||
|
||||
- ['LFS_O_WRONLY \| LFS_O_CREAT \| LFS_O_APPEND', '"ab"']
|
||||
- ['LFS_O_WRONLY \| LFS_O_TRUNC', '"wb"']
|
||||
- ['LFS_O_CREAT \| LFS_O_WRONLY', '"wb"']
|
||||
- ['LFS_O_WRONLY \| LFS_O_CREAT', '"wb"']
|
||||
- ['LFS_O_RDONLY', '"rb"']
|
||||
- ['LFS_O_RDWR', '"r+b"']
|
||||
33
storage/filesystem/littlefs/tests/TESTS/util/stats.py
Normal file
33
storage/filesystem/littlefs/tests/TESTS/util/stats.py
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import re
|
||||
import sys
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
def main(*args):
|
||||
with open('main.cpp') as file:
|
||||
tests = file.read()
|
||||
|
||||
cases = []
|
||||
with open('template_all_names.txt') as file:
|
||||
while True:
|
||||
name = file.readline().strip('\n')
|
||||
desc = file.readline().strip('\n')
|
||||
if name == 'test_results':
|
||||
break
|
||||
|
||||
cases.append((name, desc))
|
||||
|
||||
with open('template_wrapper.fmt') as file:
|
||||
template = file.read()
|
||||
|
||||
with open('main.cpp', 'w') as file:
|
||||
file.write(template.format(
|
||||
tests=tests,
|
||||
test_cases='\n'.join(
|
||||
4*' '+'Case("{desc}", {name}),'.format(
|
||||
name=name, desc=desc) for name, desc in cases)))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(*sys.argv[1:])
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
{{
|
||||
{test}
|
||||
}}
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
void {test_name}() {{
|
||||
int res = bd.init();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
{test}
|
||||
res = bd.deinit();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
}}
|
||||
@@ -0,0 +1,86 @@
|
||||
#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
|
||||
#define MBED_TEST_BLOCKDEVICE SPIFBlockDevice
|
||||
#define MBED_TEST_BLOCKDEVICE_DECL SPIFBlockDevice bd(PTE2, PTE4, PTE1, PTE5)
|
||||
#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 120
|
||||
#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
|
||||
{tests}
|
||||
|
||||
|
||||
// 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[] = {{
|
||||
{test_cases}
|
||||
}};
|
||||
|
||||
Specification specification(test_setup, cases);
|
||||
|
||||
int main() {{
|
||||
return !Harness::run(specification);
|
||||
}}
|
||||
48
storage/filesystem/littlefs/tests/TESTS/util/test.py
Normal file
48
storage/filesystem/littlefs/tests/TESTS/util/test.py
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import re
|
||||
import sys
|
||||
import subprocess
|
||||
import os
|
||||
import yaml
|
||||
|
||||
def generate(test):
|
||||
with open('replacements.yml') as file:
|
||||
replacements = yaml.load(file)
|
||||
|
||||
lines = []
|
||||
for line in re.split('(?<=[;{}])\n', test.read()):
|
||||
for pattern, replacement in replacements:
|
||||
line = re.sub(pattern, replacement, line, 0, re.DOTALL | re.MULTILINE)
|
||||
|
||||
match = re.match('(?: *\n)*( *)(.*)=>(.*);', line, re.DOTALL | re.MULTILINE)
|
||||
if match:
|
||||
tab, test, expect = match.groups()
|
||||
lines.append(tab+'res = {test};'.format(test=test.strip()))
|
||||
lines.append(tab+'TEST_ASSERT_EQUAL({expect}, res);'.format(
|
||||
name=re.match('\w*', test.strip()).group(),
|
||||
expect=expect.strip()))
|
||||
else:
|
||||
lines.append(line)
|
||||
|
||||
lines = lines[:-1]
|
||||
|
||||
with open('template_subunit.fmt') as file:
|
||||
template = file.read()
|
||||
|
||||
with open('main.cpp', 'a') as file:
|
||||
file.write(template.format(
|
||||
test=('\n'.join(
|
||||
4*' '+line.replace('\n', '\n'+4*' ')
|
||||
for line in lines))))
|
||||
|
||||
def main(test=None):
|
||||
if test and not test.startswith('-'):
|
||||
with open(test) as file:
|
||||
generate(file)
|
||||
else:
|
||||
generate(sys.stdin)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(*sys.argv[1:])
|
||||
Reference in New Issue
Block a user