* @param[in] ini will be casted to iniparser::dictionary *
*/
int loadNetworkConfig(void *ini);
+
+ bool loadedFromConfig; /**< Check if config is loaded to prevent load twice */
};
} /* namespace nntrainer */
continue_train(false),
iter(0),
initialized(false),
- def_name_count(0) {}
+ def_name_count(0),
+ loadedFromConfig(false) {}
NeuralNetwork::NeuralNetwork(std::string config) : NeuralNetwork() {
this->setConfig(config);
}
int NeuralNetwork::loadFromConfig() {
+ if (loadedFromConfig == true) {
+ ml_loge("cannnot do loadFromConfig twice");
+ return ML_ERROR_INVALID_PARAMETER;
+ }
+
int status = ML_ERROR_NONE;
std::string ini_file = config;
int num_ini_sec = 0;
return ML_ERROR_INVALID_PARAMETER;
}
+ /// @fixme: move this to end of function after resolving #382
+ loadedFromConfig = true;
+
ml_logd("parsing ini started");
/** Get all the section names */
ml_logi("==========================parsing ini...");
}
}
+/**
+ * @brief Negative test given ini is failing at loadingTwice
+ */
+TEST_P(nntrainerIniTest, loadConfigTwice) {
+ std::cout << std::get<0>(GetParam()) << std::endl;
+ NN.loadFromConfig();
+ int status = NN.loadFromConfig();
+ EXPECT_EQ(status, ML_ERROR_INVALID_PARAMETER);
+}
+
/**
* @brief check given ini is failing/succeeding at init
*/
EXPECT_NE(status, ML_ERROR_NONE);
}
+/**
+ * @brief check given ini is failing/succeeding when init happens three times.
+ * this should fail at all time.
+ */
+TEST_P(nntrainerIniTest, initThreetime_n) {
+ std::cout << std::get<0>(GetParam()) << std::endl;
+ int status = NN.loadFromConfig();
+ status = NN.init();
+ status = NN.init();
+ status = NN.init();
+
+ EXPECT_NE(status, ML_ERROR_NONE);
+}
+
/// @todo add run test could be added with iniTest flag to control skip
static IniSection nw_base("network", "Type = NeuralNetwork | "