VOL-1424: Adtran Test Framework for ONU
Change-Id: I2a2b64383e982d5e7848f84dcadcbe947e241325
diff --git a/voltha/adapters/adtran_onu/Makefile b/voltha/adapters/adtran_onu/Makefile
new file mode 100644
index 0000000..bbd25fb
--- /dev/null
+++ b/voltha/adapters/adtran_onu/Makefile
@@ -0,0 +1 @@
+include test.mk
\ No newline at end of file
diff --git a/voltha/adapters/adtran_onu/pytest.ini b/voltha/adapters/adtran_onu/pytest.ini
new file mode 100644
index 0000000..79ffd10
--- /dev/null
+++ b/voltha/adapters/adtran_onu/pytest.ini
@@ -0,0 +1,23 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+
+[pytest]
+addopts = --cov=. --cov-config=.coveragerc --cov-report html --cov-report term-missing
+ --doctest-modules -vv --junit-xml junit-coverage.xml
+doctest_optionflags = NORMALIZE_WHITESPACE ELLIPSIS
+norecursedirs=
+
+filterwarnings =
+ ignore::DeprecationWarning
+ ignore::PendingDeprecationWarning
diff --git a/voltha/adapters/adtran_onu/test.mk b/voltha/adapters/adtran_onu/test.mk
new file mode 100644
index 0000000..da6b625
--- /dev/null
+++ b/voltha/adapters/adtran_onu/test.mk
@@ -0,0 +1,72 @@
+THIS_MAKEFILE := $(abspath $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
+WORKING_DIR := $(dir $(THIS_MAKEFILE) )
+ADAPTER_NAME := $(notdir $(patsubst %/,%,$(WORKING_DIR)))
+ADAPTERS_DIR := $(dir $(patsubst %/,%,$(WORKING_DIR)))
+VOLTHA_DIR := $(dir $(patsubst %/,%,$(ADAPTERS_DIR)))
+export VOLTHA_BASE := $(VOLTHA_DIR)../
+GIT_DIR := $(dir $(patsubst %/,%,$(VOLTHA_DIR))).git
+
+OPENOLT_DIR := $(ADAPTERS_DIR)openolt
+OPENOLT_PROTO := $(shell find $(OPENOLT_DIR)/protos/ -name '*.proto')
+OPENOLT_PB2 := $(patsubst %.proto,%_pb2.py,$(OPENOLT_PROTO))
+
+VOLTHA_PROTO := $(shell find $(VOLTHA_DIR)protos -name '*.proto')
+VOLTHA_PB2 := $(patsubst %.proto,%_pb2.py,$(VOLTHA_PROTO))
+
+VENVDIR =$(VOLTHA_BASE)venv-$(shell uname -s | tr '[:upper:]' '[:lower:]')
+TESTDIR =$(WORKING_DIR)test
+IN_VENV :=. '$(VENVDIR)/bin/activate';
+TEST_REQ_INSTALLED := $(VENVDIR)/.$(ADAPTER_NAME)-test
+
+RUN_PYTEST=$(IN_VENV) PYTHONPATH=$(VOLTHA_BASE):$(VOLTHA_DIR)protos/third_party py.test -vvlx
+
+.PHONY: test
+test: requirements hooks
+ @rm -rf $(TESTDIR)/__pycache__
+ @cd $(WORKING_DIR); $(RUN_PYTEST) $(TESTDIR); coverage xml
+
+.PHONY: clean
+clean:
+ @-rm -rf .coverage
+ @-rm -rf htmlcov
+ @-rm -rf *coverage.xml
+ @-rm -rf .pytest_cache
+ @-find $(WORKING_DIR) -type f -name '*.pyc' -delete
+ @-find $(VOLTHA_DIR)protos -type f -name '*_pb2.py' -delete
+ @-find $(OPENOLT_DIR)/protos -type f -name '*_pb2.py' -delete
+
+.PHONY: lint
+lint: requirements
+ @-$(IN_VENV) pylint `pwd`
+
+.PHONY: create-venv
+create-venv: $(VENVDIR)/.built
+
+
+$(VENVDIR)/.built:
+ cd $(VOLTHA_BASE); make venv
+
+$(OPENOLT_PB2): %_pb2.py : %.proto
+ @echo !-- Making $(@) because $< changed ---
+ @cd $(OPENOLT_DIR); $(IN_VENV) $(MAKE)
+
+$(VOLTHA_PB2): %_pb2.py : %.proto
+ @echo !-- Making $(@) because $< changed ---
+ @cd $(VOLTHA_DIR)/protos; $(IN_VENV) $(MAKE) third_party build
+
+$(TEST_REQ_INSTALLED): $(WORKING_DIR)test_requirements.txt \
+ $(VOLTHA_BASE)requirements.txt
+ @$(IN_VENV) pip install --upgrade -r $(WORKING_DIR)test_requirements.txt
+ @ virtualenv -p python2 --relocatable ${VENVDIR}
+ uname -s > ${@};
+
+.PHONY: requirements
+requirements: create-venv $(OPENOLT_PB2) $(VOLTHA_PB2) $(TEST_REQ_INSTALLED)
+
+.PHONY: hooks
+hooks: $(GIT_DIR)/hooks/commit-msg
+ @echo "Commit hooks installed"
+
+$(GIT_DIR)/hooks/commit-msg:
+ @curl https://gerrit.opencord.org/tools/hooks/commit-msg > $(GIT_DIR)/hooks/commit-msg
+ @chmod u+x $(GIT_DIR)/hooks/commit-msg
diff --git a/voltha/adapters/adtran_onu/test/__init__.py b/voltha/adapters/adtran_onu/test/__init__.py
new file mode 100644
index 0000000..18d64b2
--- /dev/null
+++ b/voltha/adapters/adtran_onu/test/__init__.py
@@ -0,0 +1,13 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
diff --git a/voltha/adapters/adtran_onu/test/test_example.py b/voltha/adapters/adtran_onu/test/test_example.py
new file mode 100644
index 0000000..57a4186
--- /dev/null
+++ b/voltha/adapters/adtran_onu/test/test_example.py
@@ -0,0 +1,18 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# 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.
+
+from voltha.adapters.adtran_onu import adtran_onu
+
+def test_example():
+ assert True
diff --git a/voltha/adapters/adtran_onu/test_requirements.txt b/voltha/adapters/adtran_onu/test_requirements.txt
new file mode 100644
index 0000000..a336cc3
--- /dev/null
+++ b/voltha/adapters/adtran_onu/test_requirements.txt
@@ -0,0 +1,5 @@
+-r ../../../requirements.txt
+pytest < 4.1
+pytest-cov
+pytest-twisted
+virtualenv
\ No newline at end of file