Skip to content
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

mmyster/feature/config kit #598

Merged
merged 4 commits into from
Apr 13, 2022
Merged

mmyster/feature/config kit #598

merged 4 commits into from
Apr 13, 2022

Conversation

MMyster
Copy link
Contributor

@MMyster MMyster commented Mar 17, 2022

  • ✨ (file_system_kit): Add 'ConfigKit'
  • ✨ (config_kit): Add 'ConfigKit'

@codecov
Copy link

codecov bot commented Mar 17, 2022

Codecov Report

Merging #598 (b48cae8) into develop (fe54bcf) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop     #598      +/-   ##
===========================================
+ Coverage    98.16%   98.18%   +0.01%     
===========================================
  Files           92       94       +2     
  Lines         1966     1985      +19     
===========================================
+ Hits          1930     1949      +19     
  Misses          36       36              
Impacted Files Coverage Δ
libs/ConfigKit/include/Config.h 100.00% <100.00%> (ø)
libs/ConfigKit/source/Config.cpp 100.00% <100.00%> (ø)

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@github-actions
Copy link

github-actions bot commented Mar 17, 2022

File comparision analysis report

🔖 Info

Target Flash Used (%) Flash Available (%) Static RAM (%)
bootloader 145244 (55%) 116900 (44%) 30048 (5%)
os 294244 (18%) 1270428 (81%) 32320 (6%)
Click to show memory sections
| -          |      Hex |     Bytes |  KiB |
|------------|---------:|----------:|-----:|
| Flash      | 0x200000 | 2 097 152 | 2048 |
| SRAM       |  0x80000 |   524 288 |  512 |
| Bootloader |  0x40000 |   262 144 |  256 |
| Header     |   0x1000 |     4 096 |    4 |
| OS         | 0x17E000 | 1 564 672 | 1528 |
| Tail       |   0x1000 |     4 096 |    4 |
| Scratch    |  0x40000 |   262 144 |  256 |

📝 Summary

Click to show summary
  • ✔️ - existing target
  • ✨ - new target
  • ⚰️ - deleted target
  • ✅ - files are the same
  • ❌ - files are different
Target Status .bin .map Total Flash (base/head) Total Flash Δ Static RAM (base/head) Static RAM Δ
LekaOS ✔️ 294244 (14%) ø 32320 (6%) ø
bootloader ✔️ 145244 (6%) ø 30048 (5%) ø
certs_emc_ble_bt_lcd_led_motors ✔️ 250688 (11%) ø 29240 (5%) ø
certs_emc_ble_led_motors ✔️ 174568 (8%) ø 24952 (4%) ø
certs_emc_bt_lcd_qspi_rfid_touch_wifi ✔️ 148840 (7%) ø 22528 (4%) ø
certs_emc_lcd_led_motors ✔️ 91928 (4%) ø 16168 (3%) ø
hardware_motors_test_reduction_and_wheels ✔️ 177960 (8%) ø 24360 (4%) ø
spike_lk_behavior_kit ✔️ 142592 (6%) ø 15704 (2%) ø
spike_lk_ble ✔️ 174892 (8%) ø 24672 (4%) ø
spike_lk_bluetooth ✔️ 73256 (3%) ø 11448 (2%) ø
spike_lk_cg_animations ✔️ 141016 (6%) ø 24416 (4%) ø
spike_lk_color_kit ✔️ 65712 (3%) ø 13744 (2%) ø
spike_lk_command_kit ✔️ 144856 (6%) ø 16360 (3%) ø
spike_lk_config_kit - - 124204 (5%) - 14312 (2%) -
spike_lk_coreled ✔️ 76164 (3%) ø 13688 (2%) ø
spike_lk_event_queue ✔️ 74736 (3%) ø 12072 (2%) ø
spike_lk_file_manager_kit ✔️ 103604 (4%) ø 14048 (2%) ø
spike_lk_file_reception ✔️ 326984 (15%) ø 27576 (5%) ø
spike_lk_flash_memory ✔️ 63880 (3%) ø 11448 (2%) ø
spike_lk_lcd ✔️ 142664 (6%) ø 23992 (4%) ø
spike_lk_led ✔️ 65744 (3%) ø 13392 (2%) ø
spike_lk_led_kit ✔️ 103220 (4%) ø 14664 (2%) ø
spike_lk_log_kit ✔️ 68528 (3%) ø 11912 (2%) ø
spike_lk_motors ✔️ 62528 (2%) ø 11488 (2%) ø
spike_lk_reinforcer ✔️ 101996 (4%) ø 14664 (2%) ø
spike_lk_rfid ✔️ 73072 (3%) ø 11448 (2%) ø
spike_lk_sensors_battery ✔️ 78196 (3%) ø 12568 (2%) ø
spike_lk_sensors_light ✔️ 60056 (2%) ø 11440 (2%) ø
spike_lk_sensors_microphone ✔️ 72496 (3%) ø 11504 (2%) ø
spike_lk_sensors_temperature_humidity ✔️ 66968 (3%) ø 11424 (2%) ø
spike_lk_sensors_touch ✔️ 68600 (3%) ø 11432 (2%) ø
spike_lk_serial_number ✔️ 58904 (2%) ø 11464 (2%) ø
spike_lk_ticker_timeout ✔️ 69052 (3%) ø 11632 (2%) ø
spike_lk_update_process_app_base ✔️ 122788 (5%) ø 15288 (2%) ø
spike_lk_update_process_app_update ✔️ 77632 (3%) ø 12352 (2%) ø
spike_lk_wifi ✔️ 116392 (5%) ø 14808 (2%) ø
spike_mbed_blinky ✔️ 57968 (2%) ø 11400 (2%) ø
spike_mbed_watchdog_ticker_vs_thread ✔️ 63208 (3%) ø 12448 (2%) ø
spike_stl_cxxsupport ✔️ 58456 (2%) ø 11400 (2%) ø

🗺️ Map files diff output

Click to show diff list
spike_lk_config_kit (click to expand)

Flash used: 124204&nbsp;(5%) / total: 2097152
SRAM used: 14312&nbsp;(2%) / total: 524288

@github-actions
Copy link

github-actions bot commented Mar 17, 2022

File comparision analysis report

🔖 Info

Target Flash Used (%) Flash Available (%) Static RAM (%)
bootloader 145244 (55%) 116900 (44%) 30048 (5%)
os 313168 (20%) 1251504 (79%) 38512 (7%)
Click to show memory sections
| -          |      Hex |     Bytes |  KiB |
|------------|---------:|----------:|-----:|
| Flash      | 0x200000 | 2 097 152 | 2048 |
| SRAM       |  0x80000 |   524 288 |  512 |
| Bootloader |  0x40000 |   262 144 |  256 |
| Header     |   0x1000 |     4 096 |    4 |
| OS         | 0x17E000 | 1 564 672 | 1528 |
| Tail       |   0x1000 |     4 096 |    4 |
| Scratch    |  0x40000 |   262 144 |  256 |

📝 Summary

Click to show summary
  • ✔️ - existing target
  • ✨ - new target
  • ⚰️ - deleted target
  • ✅ - files are the same
  • ❌ - files are different
Target Status .bin .map Total Flash (base/head) Total Flash Δ Static RAM (base/head) Static RAM Δ
LekaOS ✔️ 313168 (14%) ø 38512 (7%) ø
bootloader ✔️ 145244 (6%) ø 30048 (5%) ø
certs_emc_ble_bt_lcd_led_motors ✔️ 258248 (12%) ø 35272 (6%) ø
certs_emc_ble_led_motors ✔️ 191600 (9%) ø 30976 (5%) ø
certs_emc_bt_lcd_qspi_rfid_touch_wifi ✔️ 165248 (7%) ø 28680 (5%) ø
certs_emc_lcd_led_motors ✔️ 91928 (4%) ø 16168 (3%) ø
hardware_motors_test_reduction_and_wheels ✔️ 194032 (9%) ø 30384 (5%) ø
spike_lk_behavior_kit ✔️ 151960 (7%) ø 21648 (4%) ø
spike_lk_ble ✔️ 184576 (8%) ø 30752 (5%) ø
spike_lk_bluetooth ✔️ 91192 (4%) ø 17472 (3%) ø
spike_lk_cg_animations ✔️ 149224 (7%) ø 30416 (5%) ø
spike_lk_color_kit ✔️ 88992 (4%) ø 19744 (3%) ø
spike_lk_command_kit ✔️ 156688 (7%) ø 22560 (4%) ø
spike_lk_config_kit - - 136740 (6%) - 20368 (3%) -
spike_lk_coreled ✔️ 88556 (4%) ø 19632 (3%) ø
spike_lk_event_queue ✔️ 84664 (4%) ø 18136 (3%) ø
spike_lk_file_manager_kit ✔️ 127820 (6%) ø 20216 (3%) ø
spike_lk_file_reception ✔️ 331692 (15%) ø 33536 (6%) ø
spike_lk_flash_memory ✔️ 87352 (4%) ø 17512 (3%) ø
spike_lk_lcd ✔️ 155608 (7%) ø 30064 (5%) ø
spike_lk_led ✔️ 88808 (4%) ø 19400 (3%) ø
spike_lk_led_kit ✔️ 115724 (5%) ø 20608 (3%) ø
spike_lk_log_kit ✔️ 92000 (4%) ø 18168 (3%) ø
spike_lk_motors ✔️ 86576 (4%) ø 17552 (3%) ø
spike_lk_reinforcer ✔️ 111852 (5%) ø 20608 (3%) ø
spike_lk_rfid ✔️ 91008 (4%) ø 17472 (3%) ø
spike_lk_sensors_battery ✔️ 87600 (4%) ø 18584 (3%) ø
spike_lk_sensors_light ✔️ 84584 (4%) ø 17512 (3%) ø
spike_lk_sensors_microphone ✔️ 85336 (4%) ø 17512 (3%) ø
spike_lk_sensors_temperature_humidity ✔️ 90896 (4%) ø 17496 (3%) ø
spike_lk_sensors_touch ✔️ 92248 (4%) ø 17632 (3%) ø
spike_lk_serial_number ✔️ 82752 (3%) ø 17648 (3%) ø
spike_lk_ticker_timeout ✔️ 83224 (3%) ø 17592 (3%) ø
spike_lk_update_process_app_base ✔️ 145268 (6%) ø 21352 (4%) ø
spike_lk_update_process_app_update ✔️ 100968 (4%) ø 18472 (3%) ø
spike_lk_wifi ✔️ 131280 (6%) ø 20832 (3%) ø
spike_mbed_blinky ✔️ 57968 (2%) ø 11400 (2%) ø
spike_mbed_watchdog_ticker_vs_thread ✔️ 84688 (4%) ø 18448 (3%) ø
spike_stl_cxxsupport ✔️ 84000 (4%) ø 17536 (3%) ø

🗺️ Map files diff output

Click to show diff list
spike_lk_config_kit (click to expand)

Flash used: 136740&nbsp;(6%) / total: 2097152
SRAM used: 20368&nbsp;(3%) / total: 524288

Copy link
Member

@ladislas ladislas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merci @MMyster pour cette nouvelle implémentation! 👍

c'est beaucoup mieux que la première fois, beaucoup plus clair et beaucoup plus facile à utiliser.

j'ai fait pas mal de retours pour simplifier la lecture du code + quelques uns plus structuels.

N'hésite pas à poser des questions ici ou sur slack si ce n'est pas clair.

libs/ConfigKit/include/ConfigKit.h Outdated Show resolved Hide resolved
libs/ConfigKit/include/ConfigKit.h Outdated Show resolved Hide resolved
libs/ConfigKit/include/ConfigKit.h Outdated Show resolved Hide resolved
libs/ConfigKit/include/ConfigKit.h Outdated Show resolved Hide resolved
libs/ConfigKit/include/ConfigKit.h Outdated Show resolved Hide resolved
libs/ConfigKit/tests/Config_test.cpp Outdated Show resolved Hide resolved
libs/ConfigKit/tests/Config_test.cpp Outdated Show resolved Hide resolved
libs/ConfigKit/tests/Config_test.cpp Outdated Show resolved Hide resolved
spikes/lk_config_kit/main.cpp Outdated Show resolved Hide resolved
libs/FileSystemKit/include/FileSystemKit.h Outdated Show resolved Hide resolved
@MMyster MMyster force-pushed the mmyster/feature/config_kit branch 11 times, most recently from dcfcdc0 to 1871cf4 Compare April 7, 2022 09:18
Copy link
Member

@ladislas ladislas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merci @MMyster pour les modifications! c'est vraiment très bien!

j'ai fait quelques remarques finales, j'aimerais que @YannLocatelli jette un coup d'oeil aussi.

et on sera bon pour merge! :)

Comment on lines 11 to 15
namespace leka::ConfigList {

const Config bootloader_battery_level_hysteresis("bootloader_battery_level_hysteresis");

} // namespace leka::ConfigList
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
namespace leka::ConfigList {
const Config bootloader_battery_level_hysteresis("bootloader_battery_level_hysteresis");
} // namespace leka::ConfigList
namespace leka::config {
namespace bootloader {
inline constexpr auto battery_level_hysteresis = Config {"bootloader_battery_level_hysteresis"};
} // namespace bootloader
} // namespace leka::config

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avec le default dans le ctor

inline constexpr auto battery_level_hysteresis = Config {"bootloader_battery_level_hysteresis", 42};

}
auto input = std::array<uint8_t, 1> {};
_file.read(input);
_file.close();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tu as besoin de close à chaque fois?

si une file est déjà is_open et que tu essayes d'open("new_file"), il se passe quoi?

je suis un peu gêné par le open/close qui est assez redondant.

j'ai presque envie d'avoir le file sur le stack et quand ça sort du scope, le destructor est détruit et ça ferme le fichier automatiquement.

qu'en penses-tu?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le fait d'instancier un objet FileManagerKit::File à chaque appel de fonction read/write ne risque pas d'être trop lourd?

Pour le point à propos de l'utilité du close, ça pourrait être intéressant de faire le test en écrivant sur 2 fichiers à la fois sans fermer l'un l'autre pour voir ce qu'il s'y passe.
Mais si on ne close jamais, est-ce raisonnable de garder les n fichiers ouverts pour les n configurations?


struct Config {
public:
explicit Config(const std::filesystem::path &path) : _path(_default_parent_path / path) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

il faut que tu prennes le _default_value dans le constructeur pour pouvoir avoir des différents en fonction de la config

@ladislas ladislas added the 01 - type: task Something to do label Apr 7, 2022
@ladislas ladislas added this to the v1.0.0 milestone Apr 7, 2022
Copy link
Member

@YannLocatelli YannLocatelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Juste une suggestion par rapport à l'ordre des arguments pour write sinon ça me semble très bien :)

@@ -0,0 +1,28 @@
# Leka - LekaOS
# Copyright 2021 APF France handicap
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Copyright 2021 APF France handicap
# Copyright 2022 APF France handicap

@@ -0,0 +1,70 @@
// Leka - LekaOS
// Copyright 2020 APF France handicap
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Copyright 2020 APF France handicap
// Copyright 2022 APF France handicap

@@ -0,0 +1,38 @@
// Leka - LekaOS
// Copyright 2021 APF France handicap
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Copyright 2021 APF France handicap
// Copyright 2022 APF France handicap

log_info("A message from your board %s --> \"%s\" at %i s", MBED_CONF_APP_TARGET_NAME, hello.world,
int(t.count() / 1000));

if (auto write = configkit.write(i++, ConfigList::bootloader_battery_level_hysteresis); !write) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'aurai tendance à donner d'abord l'argument du fichier avant de donner la data plutôt que l'inverse, c'est plus intuitif d'indiquer le contenant avant le contenu

Suggested change
if (auto write = configkit.write(i++, ConfigList::bootloader_battery_level_hysteresis); !write) {
if (auto write = configkit.write(ConfigList::bootloader_battery_level_hysteresis, i++); !write) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

je suis d'accord!

@MMyster il y a aussi un code smell pour i++

je pense que tu veux ++i et pas i++ et ensuite il faut faire l'assignment avant comme demande sonarcloud

see https://gcc.godbolt.org/z/11zzfcha4

}
auto input = std::array<uint8_t, 1> {};
_file.read(input);
_file.close();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le fait d'instancier un objet FileManagerKit::File à chaque appel de fonction read/write ne risque pas d'être trop lourd?

Pour le point à propos de l'utilité du close, ça pourrait être intéressant de faire le test en écrivant sur 2 fichiers à la fois sans fermer l'un l'autre pour voir ce qu'il s'y passe.
Mais si on ne close jamais, est-ce raisonnable de garder les n fichiers ouverts pour les n configurations?

Comment on lines 21 to 22
auto input = std::array<uint8_t, 1> {};
_file.read(input);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question bête peut-être, pourquoi avoir utilisé un std::array plutôt que directement un uint8_t?

Suggested change
auto input = std::array<uint8_t, 1> {};
_file.read(input);
auto input = uint8_t {0};
_file.read(input, 1);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

La fonction prend un std::span en paramètre. Dans les tests, je n'utilisais que des pointeurs ou des std::array pour les fonctions read et write.

Comment on lines 52 to 68
TEST_F(ConfigTest, initializationConfig)
{
Config config {config_path};
ASSERT_NE(nullptr, &config);
const std::filesystem::path expected_path = "/tmp/test_config.conf";
ASSERT_EQ(expected_path, config.path());
}

TEST_F(ConfigTest, initializationWithDefaultParentPathConfig)
{
const std::filesystem::path new_config_path = "test_config.conf";
Config config {new_config_path};
ASSERT_NE(nullptr, &config);
const std::filesystem::path expected_path = "/fs/conf/test_config.conf";
ASSERT_EQ(expected_path, config.path());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ca m'a pris un peu de temps à comprendre qu'il y avait 2 comportements possibles pour le constructeur selon ce que tu passais, c'est très intéressant !

Je suggérerai d'ajouter dans le premier test comme dans le second un
const std::filesystem::path new_config_path = "/tmp/test_config.conf";

Et éventuellement préciser les noms pour bien faire la différence de comportement

// In initializationConfig
const std::filesystem::path custom_full_path = "/tmp/test_config.conf";

// In initializationWithDefaultParentPathConfig
const std::filesystem::path custom_filename = "test_config.conf";

file.close();
}

void spy_touchConfigFile()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pourquoi touch?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

touch filename c'est la commande pour créer un fichier sur unix

spy_removeConfigFile();
spy_touchConfigFile();
auto data = configkit.read(config);
ASSERT_EQ(0, data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si le fichier ne contient aucun byte de donnée, c'est ConfigKit qui définit la valeur 0 par défaut?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c'est une bonne question !

est-ce que pas de valeur == 0 ou == default_value.

je pencherai pour default_value puisque pas de fichier ou rien dedans c'est un peu la même chose --> la config n'existe pas vraiment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valeur = 0

Rien n'est lue effectivement mais la variable input est vide par défault (donc élément 0 par défault)

@MMyster MMyster force-pushed the mmyster/feature/config_kit branch 2 times, most recently from 10ed30c to 4d016d2 Compare April 8, 2022 15:33
@MMyster MMyster force-pushed the mmyster/feature/config_kit branch 5 times, most recently from 15de47f to 805bd16 Compare April 11, 2022 19:28
@ladislas ladislas merged commit e3c0075 into develop Apr 13, 2022
@ladislas ladislas deleted the mmyster/feature/config_kit branch April 13, 2022 13:30
@sonarcloud
Copy link

sonarcloud bot commented Apr 13, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
01 - type: task Something to do
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants