Skip to content

Commit

Permalink
Server version (#204)
Browse files Browse the repository at this point in the history
* Add get_server_version to COMMON

* Add target http_api

* Add server version to current instrument

* Add get_server_version to instrument_manager.py

* Check dnas

* Add comment

* add help target to Makefile

* edit makefile
  • Loading branch information
tvanderbruggen authored and jeanminet committed Jul 23, 2016
1 parent 62129a5 commit 2a0ece6
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 26 deletions.
36 changes: 25 additions & 11 deletions Makefile
Expand Up @@ -5,6 +5,17 @@
NAME = oscillo
HOST = 192.168.1.100

all: $(ZIP) $(STATIC_ZIP) $(HTTP_API_ZIP) boot.bin uImage devicetree.dtb fw_printenv tcp-server_cli

help:
@echo - server: Build the server
@echo - bd: Build the block design interactively
@echo - xpr: Build the Vivado project
@echo - bit: Build the bitstream
@echo - http: Build the HTTP API
@echo - run: Run the instrument
@echo - test: Test the instrument

###############################################################################
# Get the project configuration
# MAKE_PY script parses the properties defined MAIN_YML
Expand Down Expand Up @@ -78,15 +89,15 @@ TEMPLATE_DIR = scripts/templates

# Versioning
VERSION_FILE = $(TMP)/$(NAME).version
VERSION = $(shell cat $(VERSION_FILE))
VERSION := $(shell cat $(VERSION_FILE))
SHA_FILE = $(TMP)/$(NAME).sha
SHA = $(shell cat $(SHA_FILE))

# Zip
TCP_SERVER_DIR = $(TMP)/$(NAME).tcp-server
TCP_SERVER = $(TCP_SERVER_DIR)/tmp/kserverd
SERVER_CONFIG = projects/$(NAME)/drivers.yml
TCP_SERVER_SHA := master
TCP_SERVER_SHA = master
TCP_SERVER_VENV = $(TMP)/$(NAME).tcp_server_venv
TCP_SERVER_MIDDLEWARE = $(TMP)/$(NAME).middleware

Expand All @@ -107,20 +118,18 @@ METADATA = $(TMP)/metadata.json

.PRECIOUS: $(TMP)/cores/% $(TMP)/%.xpr $(TMP)/%.hwdef $(TMP)/%.bit $(TMP)/%.fsbl/executable.elf $(TMP)/%.tree/system.dts

.PHONY: clean all \
test_module test_core test_% test test_app test_instrum test_all \
server xpr zip app bd \
run app_sync app_sync_ssh tcp-server_cli

all: $(ZIP) $(STATIC_ZIP) $(HTTP_API_ZIP) boot.bin uImage devicetree.dtb fw_printenv tcp-server_cli

$(TMP):
mkdir -p $(TMP)

###############################################################################
# Tests
# API
###############################################################################

.PHONY: clean all \
test_module test_core test_% test test_app test_instrum test_all \
server xpr zip app bd http_api \
run app_sync app_sync_ssh tcp-server_cli

# Run Vivado interactively and build block design
bd: $(CONFIG_TCL) $(XDC) projects/$(NAME)/*.tcl $(addprefix $(TMP)/cores/, $(CORES))
vivado -nolog -nojournal -source scripts/block_design.tcl -tclargs $(NAME) $(PART) $(BOARD)
Expand Down Expand Up @@ -177,10 +186,12 @@ $(TMP)/cores/%: fpga/cores/%/core_config.tcl fpga/cores/%/*.v
$(TMP)/$(NAME).xpr: $(CONFIG_TCL) $(XDC) projects/$(NAME)/*.tcl $(addprefix $(TMP)/cores/, $(CORES))
mkdir -p $(@D)
$(VIVADO) -source scripts/project.tcl -tclargs $(NAME) $(PART) $(BOARD)
@echo [$@] OK

$(TMP)/$(NAME).bit: $(TMP)/$(NAME).xpr
mkdir -p $(@D)
$(VIVADO) -source scripts/bitstream.tcl -tclargs $(NAME)
@echo [$@] OK

###############################################################################
# first-stage boot loader
Expand Down Expand Up @@ -307,6 +318,7 @@ $(TCP_SERVER): $(MAKE_PY) $(TCP_SERVER_VENV) $(SERVER_CONFIG) \
cp -R drivers/lib $(TCP_SERVER_MIDDLEWARE)/drivers/
cd $(TCP_SERVER_DIR) && make CONFIG=$(SERVER_CONFIG) BASE_DIR=../.. \
PYTHON=$(PYTHON) MIDWARE_PATH=$(TCP_SERVER_MIDDLEWARE) clean all
@echo [$@] OK

tcp-server_cli: $(TCP_SERVER_DIR) $(TCP_SERVER_VENV)
cd $(TCP_SERVER_DIR) && make CONFIG=$(SERVER_CONFIG) BASE_DIR=../.. PYTHON=$(PYTHON) cli
Expand All @@ -330,7 +342,7 @@ $(HTTP_API_DRIVERS_DIR)/%: drivers/%/__init__.py
cp $< $@/__init__.py

$(HTTP_API_DIR): $(METADATA) $(addprefix $(HTTP_API_DRIVERS_DIR)/, $(HTTP_API_DRIVERS))
touch $(HTTP_API_DRIVERS_DIR)/__init__.py
touch $(HTTP_API_DRIVERS_DIR)/__init__.py
mkdir -p $(HTTP_API_DIR)/api_app
cp -R os/api/. $(HTTP_API_DIR)/api_app
cp $(TMP)/metadata.json $(HTTP_API_DIR)
Expand All @@ -339,6 +351,8 @@ $(HTTP_API_DIR): $(METADATA) $(addprefix $(HTTP_API_DRIVERS_DIR)/, $(HTTP_API_DR
$(HTTP_API_ZIP): $(HTTP_API_DIR)
cd $(HTTP_API_DIR) && zip -r $(HTTP_API_ZIP) .

http_api: $(HTTP_API_ZIP)

app_sync: $(HTTP_API_ZIP)
curl -v -F app-$(VERSION).zip=@$(HTTP_API_DIR)/$(HTTP_API_ZIP) http://$(HOST)/api/app/update

Expand Down
9 changes: 8 additions & 1 deletion drivers/common/__init__.py
Expand Up @@ -31,7 +31,7 @@ def get_dna(self):
def set_led(self, value): pass

@command('COMMON')
def get_led(self):
def get_led(self):
return self.client.recv_uint32()

@command('COMMON')
Expand All @@ -40,6 +40,13 @@ def init(self): pass
@command('COMMON')
def ip_on_leds(self): pass

def get_server_version(self):
@command('KSERVER')
def get_version(self):
return self.client.recv_string()

return get_version(self)

def status(self):
print('bitstream id = {}'.format(self.get_bitstream_id()))
print('DNA = {}'.format(self.get_dna()))
Expand Down
2 changes: 2 additions & 0 deletions fpga/cores/edge_detector_v1_0/edge_detector_tb.v
Expand Up @@ -18,6 +18,8 @@ module edge_detector_tb();
parameter CLK_PERIOD = 8;

initial begin
$dumpfile("test.vcd");
$dumpvars(0);
clk = 1;
din = 0;
#(10*CLK_PERIOD) din = 1;
Expand Down
3 changes: 2 additions & 1 deletion os/api/__init__.py
Expand Up @@ -202,7 +202,8 @@ def install_instrument(self, zip_filename):
# http://stackoverflow.com/questions/21936597/blocking-and-non-blocking-subprocess-calls
subprocess.call(['/bin/bash', 'api_app/install_instrument.sh', zip_filename, name])
self.start_client()
self.current_instrument = {'name': name, 'sha': sha}
self.current_instrument = {'name': name, 'sha': sha,
'server_version': self.common.get_server_version()}

if not self.is_bitstream_id_valid():
self.handle_invalid_bitstream()
Expand Down
4 changes: 4 additions & 0 deletions tests/instrument_manager.py
Expand Up @@ -71,6 +71,10 @@ def get_current_instrument(self):
print("[error] " + str(e))
return {}

def get_server_version(self):
live_instrum = self.get_current_instrument()
return live_instrum['server_version']

def install_instrument(self, instrument_name, always_restart=False):
if not always_restart:
# Don't restart the instrument if already launched
Expand Down
6 changes: 5 additions & 1 deletion tests/tests_common.py
Expand Up @@ -37,5 +37,9 @@ def test_ip_on_leds(self):
def test_get_dna(self):
assert len(common.get_dna()) == 14

def test_get_server_version(self):
assert len(common.get_server_version()) == 7

# tests = TestsCommon()
# tests.test_ip_on_leds()
# tests.test_ip_on_leds()
# tests.test_get_server_version()
29 changes: 17 additions & 12 deletions tests/tests_instrument_manager.py
Expand Up @@ -22,6 +22,9 @@ def test_get_app_version(self):
assert 'user' in version
assert 'version' in version

def test_get_server_version(self):
assert im.get_server_version() == common.get_server_version()

def test_get_bistream_id(self):
assert im.get_bistream_id() == common.get_bitstream_id()

Expand All @@ -36,26 +39,28 @@ def test_remove_and_restore(self):
local_instruments = im.get_local_instruments()

for instrum in local_instruments:
if len(local_instruments[instrum]) > 0:
for version in local_instruments[instrum]:
im.remove_local_instrument(instrum, version)
# Check the instrument has been deleted
new_instruments = im.get_local_instruments()
assert instrum not in new_instruments or version not in new_instruments[instrum]
for version in local_instruments[instrum]:
im.remove_local_instrument(instrum, version)
# Check the instrument has been deleted
new_instruments = im.get_local_instruments()
assert instrum not in new_instruments or version not in new_instruments[instrum]

im.restore_backup()
assert len(im.get_local_instruments()) > 0

def test_install_instruments(self):
local_instruments = im.get_local_instruments()
dnas = []

for instrum in local_instruments:
if len(local_instruments[instrum]) > 0:
for version in local_instruments[instrum]:
im.deploy_local_instrument(instrum, version)
curr_instrum = im.get_current_instrument()
assert curr_instrum['name'] == instrum
assert curr_instrum['sha'] == version
for version in local_instruments[instrum]:
im.deploy_local_instrument(instrum, version)
curr_instrum = im.get_current_instrument()
dnas.append(im.get_dna())
assert dnas[0] == dnas[-1] # DNA is independent of the instrument
assert curr_instrum['name'] == instrum
assert curr_instrum['sha'] == version


tests = TestsInstrumentManager()
tests.test_get_app_version()
Expand Down

0 comments on commit 2a0ece6

Please sign in to comment.