[VOL-1787] :
This commit sets up a unit-test framework for openolt
agent based on gtest, gmock and c-mock utilities.
A sample unit-test case to test EnableOlt success case is also
added. More test cases will be added in future commit.
Change-Id: If020be489a04d97df5fcbc15e9207deeee2fcfac
diff --git a/agent/test/inc/bal_mocker.h b/agent/test/inc/bal_mocker.h
new file mode 100644
index 0000000..99be959
--- /dev/null
+++ b/agent/test/inc/bal_mocker.h
@@ -0,0 +1,34 @@
+/*
+ Copyright (C) 2018 Open Networking Foundation
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __BAL_MOCKER_H__
+#define __BAL_MOCKER_H__
+#include <cmock/cmock.h>
+#include <cstdlib>
+#include "bcmos_errno.h"
+#include "bcmolt_host_api.h"
+#include "bcmolt_system_types_typedefs.h"
+#include "bcmolt_msg.h"
+
+class BalMocker : public CMockMocker<BalMocker>
+{
+public:
+ MOCK_METHOD1(bcmolt_host_init, bcmos_errno(bcmolt_host_init_parms*));
+ MOCK_METHOD2(bcmolt_cfg_get, bcmos_errno(bcmolt_oltid, bcmolt_cfg*));
+ MOCK_METHOD2(bcmolt_oper_submit, bcmos_errno(bcmolt_oltid, bcmolt_oper*));
+};
+#endif
diff --git a/agent/test/inc/bal_stub.h b/agent/test/inc/bal_stub.h
new file mode 100644
index 0000000..4001327
--- /dev/null
+++ b/agent/test/inc/bal_stub.h
@@ -0,0 +1,29 @@
+/*
+ Copyright (C) 2018 Open Networking Foundation
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _BAL_STUB_H_
+#define _BAl_STUB_H_
+extern "C" {
+#include <test_stub.h>
+
+
+void bcmos_usleep(uint32_t us);
+void bcmos_fastlock_init(bcmos_fastlock *lock, uint32_t flags);
+long bcmos_fastlock_lock(bcmos_fastlock *lock);
+void bcmos_fastlock_unlock(bcmos_fastlock *lock, long flags);
+}
+#endif
diff --git a/agent/test/inc/bal_version.h b/agent/test/inc/bal_version.h
new file mode 100644
index 0000000..dbeb1e7
--- /dev/null
+++ b/agent/test/inc/bal_version.h
@@ -0,0 +1,22 @@
+/*
+ Copyright (C) 2018 Open Networking Foundation
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef __BAL_VERSION_H__
+#define __BAL_VERSION_H__
+// This is stub header file for unit test case only
+
+#endif
+
diff --git a/agent/test/inc/bcm_api_cli.h b/agent/test/inc/bcm_api_cli.h
new file mode 100644
index 0000000..f0c98af
--- /dev/null
+++ b/agent/test/inc/bcm_api_cli.h
@@ -0,0 +1,22 @@
+/*
+ Copyright (C) 2018 Open Networking Foundation
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __BCMAPI_CLI_H__
+#define __BCMAPI_CLI_H__
+// This is stub header file for unit test case only
+//
+#endif
diff --git a/agent/test/inc/bcmcli.h b/agent/test/inc/bcmcli.h
new file mode 100644
index 0000000..daef962
--- /dev/null
+++ b/agent/test/inc/bcmcli.h
@@ -0,0 +1,22 @@
+/*
+ Copyright (C) 2018 Open Networking Foundation
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __BCMCLI_H__
+#define __BCMCLI_H__
+// This is stub header file for unit test case only
+//
+#endif
diff --git a/agent/test/inc/bcmcli_session.h b/agent/test/inc/bcmcli_session.h
new file mode 100644
index 0000000..0855ad5
--- /dev/null
+++ b/agent/test/inc/bcmcli_session.h
@@ -0,0 +1,49 @@
+/*
+ Copyright (C) 2018 Open Networking Foundation
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef __BCMCLI_SESSION_H__
+#define __BCMCLI_SESSION_H__
+#include "bcmos_errno.h"
+// This is a stub header file for unit test case only
+typedef int bcmcli_session;
+typedef char bcmcli_entry[50];
+typedef char bcmcli_cmd_parm;
+struct bcmos_task {
+ char task_name[50];
+};
+
+typedef struct bcmcli_session_parm {
+ void *get_prompt;
+ int access_right;
+} bcmcli_session_parm;
+
+#define BCMCLI_ACCESS_ADMIN 0xff
+#define BUG_ON //
+#define BCMCLI_MAKE_CMD_NOPARM(ptr, command1, command2, command3)
+#define BAL_API_VERSION 3
+
+
+extern bool bcmcli_is_stopped(bcmcli_session *sess);
+extern bool bcmcli_parse(bcmcli_session *sess, char *s);
+extern bool bcmcli_driver(bcmcli_session *sess);
+extern void bcmcli_token_destroy(void *);
+extern void bcmcli_session_close(bcmcli_session *sess);
+extern bcmos_errno bcm_api_cli_set_commands(bcmcli_session *sess);
+extern void bcmcli_stop(bcmcli_session *sess);
+extern void bcmcli_session_print(bcmcli_session *sess, const char *s);
+extern bcmos_errno bcmcli_session_open(bcmcli_session_parm *mon_sess, bcmcli_session **curr_sess);
+#endif
+
diff --git a/agent/test/inc/bcmolt_api_topology.h b/agent/test/inc/bcmolt_api_topology.h
new file mode 100644
index 0000000..17709ea
--- /dev/null
+++ b/agent/test/inc/bcmolt_api_topology.h
@@ -0,0 +1,23 @@
+/*
+ Copyright (C) 2018 Open Networking Foundation
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef __BCMOLT_API_TOPOLOGY_H__
+#define __BCMOLT_API_TOPOLOGY_H__
+// This is stub header file for unit test case only
+
+#endif
+
+
diff --git a/agent/test/inc/bcmolt_conn_mgr.h b/agent/test/inc/bcmolt_conn_mgr.h
new file mode 100644
index 0000000..124da6c
--- /dev/null
+++ b/agent/test/inc/bcmolt_conn_mgr.h
@@ -0,0 +1,31 @@
+/*
+ Copyright (C) 2018 Open Networking Foundation
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef __BCMOLT_CONN_MGR_H__
+#define __BCMOLT_CONN_MGR_H__
+// This is stub header file for unit tets case only
+//
+extern "C" {
+typedef char bcmolt_cm_addr[100];
+
+typedef int bcmolt_goid;
+
+typedef struct bcmos_fastlock {
+ pthread_mutex_t lock;
+} bcmos_fastlock;
+
+}
+#endif
diff --git a/agent/test/inc/test_stub.h b/agent/test/inc/test_stub.h
new file mode 100644
index 0000000..f2e87b1
--- /dev/null
+++ b/agent/test/inc/test_stub.h
@@ -0,0 +1,40 @@
+/*
+ Copyright (C) 2018 Open Networking Foundation
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef __TEST_STUB_H__
+#define __TEST_STUB_H__
+
+#include <pthread.h>
+#include <unistd.h>
+#include <stdint.h>
+
+#include "bcmolt_conn_mgr.h"
+#include "bcmcli_session.h"
+#include "bcmos_errno.h"
+
+// defines some stub definitions that are not available to openolt application
+// when compoling in TEST_MODE
+//#define BCMOLT_TM_QUEUE_KEY_TM_Q_SET_ID_DEFAULT 0
+#define MAX_SUPPORTED_PON 16
+
+
+void bcmos_usleep(uint32_t us);
+void bcmos_fastlock_init(bcmos_fastlock *lock, uint32_t flags);
+long bcmos_fastlock_lock(bcmos_fastlock *lock);
+void bcmos_fastlock_unlock(bcmos_fastlock *lock, long flags);
+
+#endif //__TEST_STUB_H__
+