Skip to content

Commit

Permalink
Merge pull request #276 from yash-ni/new-testing-suite
Browse files Browse the repository at this point in the history
Adding a new python test framework based unit test suite.
  • Loading branch information
chethanravindranath authored Jul 25, 2023
2 parents cab2938 + 2cb1143 commit 5532345
Show file tree
Hide file tree
Showing 62 changed files with 1,562 additions and 45 deletions.
89 changes: 44 additions & 45 deletions .github/workflows/build_release_artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,58 +9,57 @@ jobs:
name: Download and Build artifacts
runs-on: self-hosted
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2

- uses: actions/setup-python@v4
with:
python-version: '3.10'
- uses: actions/setup-python@v4
with:
python-version: "3.10"

- uses: actions/download-artifact@v3
id: download_artifacts
with:
path: ${{ runner.temp }}\grpc-labview-artifacts
- uses: actions/download-artifact@v3
id: download_artifacts
with:
path: ${{ runner.temp }}\grpc-labview-artifacts

- name: Stage Artifacts
run:
python ${{runner.workspace}}\grpc-labview\build-it\stage_artifacts.py --downloaded_path ${{ steps.download_artifacts.outputs.download-path }} --staging_path ${{ runner.temp }}\grpc-labview-staged-artifacts

- if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
name: Build VI Packages for Testing
run:
python ${{runner.workspace}}\grpc-labview\build-it\build.py --target All --pathToBinaries ${{ runner.temp }}\grpc-labview-staged-artifacts\TopLevelDlls
- name: Stage Artifacts
run: python ${{runner.workspace}}\grpc-labview\build-it\stage_artifacts.py --downloaded_path ${{ steps.download_artifacts.outputs.download-path }} --staging_path ${{ runner.temp }}\grpc-labview-staged-artifacts

- if: startsWith(github.ref, 'refs/tags/v')
name: Build VI Packages for release
run:
python ${{runner.workspace}}\grpc-labview\build-it\build.py --libraryVersion ${{github.ref_name}} --target All --pathToBinaries ${{ runner.temp }}\grpc-labview-staged-artifacts\TopLevelDlls
- if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
name: Build VI Packages for Testing
run: python ${{runner.workspace}}\grpc-labview\build-it\build.py --target All --pathToBinaries ${{ runner.temp }}\grpc-labview-staged-artifacts\TopLevelDlls

- if: startsWith(github.ref, 'refs/tags/v')
name: Zip Release Artifacts
run: |
cd "${{runner.workspace}}/grpc-labview/labview source/Builds"
tar -cavf grpc-labview.zip *.vip
- if: startsWith(github.ref, 'refs/tags/v')
name: Build VI Packages for release
run: python ${{runner.workspace}}\grpc-labview\build-it\build.py --libraryVersion ${{github.ref_name}} --target All --pathToBinaries ${{ runner.temp }}\grpc-labview-staged-artifacts\TopLevelDlls

- name: Run CI Tests
run:
python ${{runner.workspace}}\grpc-labview\tests\run_tests.py

- if: startsWith(github.ref, 'refs/tags/v')
name: Create Draft Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
name: Verison ${{ github.ref }}
draft: true
- if: startsWith(github.ref, 'refs/tags/v')
name: Zip Release Artifacts
run: |
cd "${{runner.workspace}}/grpc-labview/labview source/Builds"
tar -cavf grpc-labview.zip *.vip
- if: startsWith(github.ref, 'refs/tags/v')
name: Upload Release Artifacts to Draft Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
- name: Run CI Tests
run: python ${{runner.workspace}}\grpc-labview\tests\run_tests.py

- name: Run New Testing Suite's Tests
run: python ${{runner.workspace}}\grpc-labview\tests\New_ATS\pylib\run_tests.py

- if: startsWith(github.ref, 'refs/tags/v')
name: Create Draft Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
name: Verison ${{ github.ref }}
draft: true

- if: startsWith(github.ref, 'refs/tags/v')
name: Upload Release Artifacts to Draft Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{runner.workspace}}/grpc-labview/labview source/Builds/grpc-labview.zip
asset_name: grpc-labview.zip
Expand Down
11 changes: 11 additions & 0 deletions tests/New_ATS/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*.lvproj
venv
*.lvlpv
*.aliases
*.pyi
*_pb2_grpc.py
*_pb2.py
*.aliases
*.lvproj
*.lvlps
Generated_server
Binary file added tests/New_ATS/Copy RunServer.vi
Binary file not shown.
Binary file added tests/New_ATS/Copy StartSync.vi
Binary file not shown.
18 changes: 18 additions & 0 deletions tests/New_ATS/CreatePythonVirtualEnv.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@echo off
pushd %~dp0
set script_dir=%CD%
popd

echo Searching for a virtual environment...
echo.

IF NOT exist %script_dir%\venv (
echo Virtual Environment not found
echo Creating Virtual Environment at \venv
call python -m venv %script_dir%\venv
echo Installing grpcio-tools into Virtual Environment
call %script_dir%\venv\Scripts\python.exe -m pip install grpcio-tools pytest
echo Successfully Installed Virtual Environment
) ELSE (
echo Virtual Environment found
)
Binary file added tests/New_ATS/Generate Path from String Array.vi
Binary file not shown.
Binary file added tests/New_ATS/Main_CLIWrapper.vi
Binary file not shown.
9 changes: 9 additions & 0 deletions tests/New_ATS/RunPythonClient.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@echo off
set python_client_path=%1
pushd %~dp0
set script_dir=%CD%
popd

echo Running Python Client
echo %script_dir%\venv\Scripts\python.exe -m pytest %python_client_path% -vv
call %script_dir%\venv\Scripts\python.exe -m pytest %python_client_path% -vv
Binary file added tests/New_ATS/RunService_CLIWrapper.vi
Binary file not shown.
Binary file added tests/New_ATS/Start RunService.vi
Binary file not shown.
Binary file added tests/New_ATS/Stop RunService.vi
Binary file not shown.
Binary file added tests/New_ATS/TestMain.vi
Binary file not shown.
Binary file added tests/New_ATS/TestProto.vi
Binary file not shown.
Binary file added tests/New_ATS/TestResults.ctl
Binary file not shown.
Binary file not shown.
Binary file not shown.
49 changes: 49 additions & 0 deletions tests/New_ATS/Tests/all-datatypes-oneof/all-datatypes-oneof.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
syntax = "proto3";

package Greeter;

service GreeterService {
rpc GetFeature(req) returns (res) {}
}

message res {
int32 res_latitude = 1;
oneof res_oneof {
int32 res_int32 = 2;
int64 res_int64 = 3;
uint32 res_uint32 = 4;
uint64 res_uint64 = 5;
sint32 res_sint32 = 6;
sint64 res_sint64 = 7;
fixed32 res_fixed32 = 8; // fixed32 -> uint32 (always encoded using 4 bytes)
fixed64 res_fixed64 = 9; // fixed64 -> uint64 (always encoded using 8 bytes)
sfixed32 res_sfixed32 = 10; // sfixed32 -> int32 (same as above but using two's complement representation)
sfixed64 res_sfixed64 = 11; // sfixed64 -> int64 (,,)
float res_float = 12;
double res_double = 13;
bool res_bool = 14;
string res_string = 15;
bytes res_bytes = 16;
}
}

message req {
int32 req_latitude = 1;
oneof req_oneof {
int32 req_int32 = 2;
int64 req_int64 = 3;
uint32 req_uint32 = 4;
uint64 req_uint64 = 5;
sint32 req_sint32 = 6;
sint64 req_sint64 = 7;
fixed32 req_fixed32 = 8; // fixed32 -> uint32 (always encoded using 4 bytes)
fixed64 req_fixed64 = 9; // fixed64 -> uint64 (always encoded using 8 bytes)
sfixed32 req_sfixed32 = 10; // sfixed32 -> int32 (same as above but using two's complement representation)
sfixed64 req_sfixed64 = 11; // sfixed64 -> int64 (,,)
float req_float = 12;
double req_double = 13;
bool req_bool = 14;
string req_string = 15;
bytes req_bytes = 16;
}
}
100 changes: 100 additions & 0 deletions tests/New_ATS/Tests/all-datatypes-oneof/all-datatypes-oneof_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import grpc
import all_datatypes_oneof_pb2
import all_datatypes_oneof_pb2_grpc
import json
import pytest
import os

def get_GetFeature_output(test_input):

req_latitude = test_input.get('req_latitude')
req_int32 = test_input['req_oneof'].get('req_int32')
req_int64 = test_input['req_oneof'].get('req_int64')
req_uint32 = test_input['req_oneof'].get('req_uint32')
req_uint64 = test_input['req_oneof'].get('req_uint64')
req_sint32 = test_input['req_oneof'].get('req_sint32')
req_sint64 = test_input['req_oneof'].get('req_sint64')
req_fixed32 = test_input['req_oneof'].get('req_fixed32')
req_fixed64 = test_input['req_oneof'].get('req_fixed64')
req_sfixed32 = test_input['req_oneof'].get('req_sfixed32')
req_sfixed64 = test_input['req_oneof'].get('req_sfixed64')
req_float = test_input['req_oneof'].get('req_float')
req_double = test_input['req_oneof'].get('req_double')
req_bool = test_input['req_oneof'].get('req_bool')
req_string = test_input['req_oneof'].get('req_string')
req_bytes = test_input['req_oneof'].get('req_bytes')
if req_bytes is not None:
req_bytes=req_bytes.encode('utf-8')

with grpc.insecure_channel('localhost:50051') as channel:
stub = all_datatypes_oneof_pb2_grpc.GreeterServiceStub(channel)
request = all_datatypes_oneof_pb2.req(
req_latitude=req_latitude,
req_int32=req_int32,
req_int64=req_int64,
req_uint32=req_uint32,
req_uint64=req_uint64,
req_sint32=req_sint32,
req_sint64=req_sint64,
req_fixed32=req_fixed32,
req_fixed64=req_fixed64,
req_sfixed32=req_sfixed32,
req_sfixed64=req_sfixed64,
req_double=req_double,
req_float=req_float,
req_bool=req_bool,
req_string=req_string,
req_bytes=req_bytes
)
response = stub.GetFeature(request)

response_dict = {}
response_dict['res_latitude'] = response.res_latitude
response_dict['res_oneof'] = {}
if(response.HasField('res_int32')):
response_dict['res_oneof']['res_int32'] = response.res_int32
if(response.HasField('res_int64')):
response_dict['res_oneof']['res_int64'] = response.res_int64
if(response.HasField('res_uint32')):
response_dict['res_oneof']['res_uint32'] = response.res_uint32
if(response.HasField('res_uint64')):
response_dict['res_oneof']['res_uint64'] = response.res_uint64
if(response.HasField('res_sint32')):
response_dict['res_oneof']['res_sint32'] = response.res_sint32
if(response.HasField('res_sint64')):
response_dict['res_oneof']['res_sint64'] = response.res_sint64
if(response.HasField('res_fixed32')):
response_dict['res_oneof']['res_fixed32'] = response.res_fixed32
if(response.HasField('res_fixed64')):
response_dict['res_oneof']['res_fixed64'] = response.res_fixed64
if(response.HasField('res_sfixed32')):
response_dict['res_oneof']['res_sfixed32'] = response.res_sfixed32
if(response.HasField('res_sfixed64')):
response_dict['res_oneof']['res_sfixed64'] = response.res_sfixed64
if(response.HasField('res_float')):
response_dict['res_oneof']['res_float'] = response.res_float
if(response.HasField('res_double')):
response_dict['res_oneof']['res_double'] = response.res_double
if(response.HasField('res_bool')):
response_dict['res_oneof']['res_bool'] = response.res_bool
if(response.HasField('res_string')):
response_dict['res_oneof']['res_string'] = response.res_string
if(response.HasField('res_bytes')):
response_dict['res_oneof']['res_bytes'] = response.res_bytes.decode('utf-8')
return(response_dict)

def read_json(filepath):
with open(filepath, 'r') as file:
test_data = json.load(file)
return test_data

GetFeature_json_file_path = f'{os.path.dirname(os.path.abspath(__file__))}/testcases/GetFeature.json'

@pytest.mark.parametrize('testcase', read_json(GetFeature_json_file_path))
def test_SayHello(testcase):
test_input = testcase['input']
expected = testcase['output']
assert get_GetFeature_output(test_input) == expected

if __name__ == "__main__":
print(get_GetFeature_output({"req_latitude":100, "req_oneof":{"req_string":"wow"}}))
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from concurrent import futures

import grpc
import all_datatypes_oneof_pb2
import all_datatypes_oneof_pb2_grpc

class GreeterService(all_datatypes_oneof_pb2_grpc.GreeterServiceServicer):
def GetFeature(self, request, context):
response = all_datatypes_oneof_pb2.res(res_latitude=request.req_latitude+1)
if request.HasField('req_int32'):
response.res_int32 = request.req_int32 + 1
if request.HasField('req_int64'):
response.res_int64 = request.req_int64 + 1
if request.HasField('req_uint32'):
response.res_uint32 = request.req_uint32 + 1
if request.HasField('req_uint64'):
response.res_uint64 = request.req_uint64 + 1
if request.HasField('req_sint32'):
response.res_sint32 = request.req_sint32 + 1
if request.HasField('req_sint64'):
response.res_sint64 = request.req_sint64 + 1
if request.HasField('req_fixed32'):
response.res_fixed32 = request.req_fixed32 + 1
if request.HasField('req_fixed64'):
response.res_fixed64 = request.req_fixed64 + 1
if request.HasField('req_sfixed32'):
response.res_sfixed32 = request.req_sfixed32 + 1
if request.HasField('req_sfixed64'):
response.res_sfixed64 = request.req_sfixed64 + 1
if request.HasField('req_float'):
response.res_float = request.req_float + 1
if request.HasField('req_double'):
response.res_double = request.req_double + 1
if request.HasField('req_bool'):
response.res_bool = False if request.req_bool else True
if request.HasField('req_string'):
response.res_string = request.req_string + "_response"
if request.HasField('req_bytes'):
response.res_bytes = request.req_bytes
return response

def server():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=2))
all_datatypes_oneof_pb2_grpc.add_GreeterServiceServicer_to_server(GreeterService(), server)
server.add_insecure_port('[::]:50051')
print("gRPC starting")
server.start()
server.wait_for_termination()

if __name__ == "__main__":
server()
Loading

0 comments on commit 5532345

Please sign in to comment.