aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.UnitTesting/RemoteRunner_TST.cs
blob: 9b2251a512422133b035291e560b4c2061030096 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Tango.Transport;
using Tango.Transport.Transporters;
using Tango.Transport.Adapters;
using Tango.PMR.IO;
using Tango.PMR;
using Google.Protobuf;
using Tango.Transport.Discovery;
using Tango.PMR.Discovery;

namespace Tango.UnitTesting
{
    [TestClass]
    [TestCategory("Remote Runner")]
    public class RemoteRunner_TST 
    {
        [TestMethod]
        public void Run_Remote_Runner_Connect_Upload_And_Execute_Process()
        {
            Process runner = Process.Start(Path.Combine(Helper.GetBuildPath(), "Tango.RemoteRunner.UI.exe"));
            runner.WaitForInputIdle();

            Thread.Sleep(2000);

            UdpDiscoveryClient<BasicDiscoveryMessage> discoveryClient = new UdpDiscoveryClient<BasicDiscoveryMessage>(2018);
            var discoveryResponse = discoveryClient.Discover().Result;

            ITransportAdapter adapter = new TcpTransportAdapter(discoveryResponse.Address, discoveryResponse.Message.Port);
            ITransporter transporter = new BasicTransporter(adapter);
            transporter.Connect().Wait();

            Thread.Sleep(1000);

            String uploadFileName = "RemoteRunnerExeTest.zip";
            String executeFileName = "RemoteRunnerExeTest.exe";

            System.IO.FileInfo exeFile = new System.IO.FileInfo(Helper.GetResourcePath(uploadFileName));

            var uploadResponse = transporter.SendRequest<FileUploadRequest, FileUploadResponse>(new FileUploadRequest()
            {
                FileName = uploadFileName,
                Length = exeFile.Length,
            }).Result.Message;

            int currentFilePosition = 0;

            do
            {
                using (FileStream fs = new FileStream(exeFile.FullName, FileMode.Open))
                {
                    fs.Position = currentFilePosition;

                    FileChunkUploadRequest chunkRequest = new FileChunkUploadRequest();
                    chunkRequest.UploadID = uploadResponse.UploadID;

                    long remaining = exeFile.Length - currentFilePosition;

                    byte[] buffer = new byte[uploadResponse.MaxChunkLength < remaining ? uploadResponse.MaxChunkLength : remaining];
                    fs.Read(buffer, 0, buffer.Length);
                    chunkRequest.Buffer = ByteString.CopyFrom(buffer);

                    transporter.SendRequest<FileChunkUploadRequest, FileChunkUploadResponse>(chunkRequest).Wait();

                    currentFilePosition += buffer.Length;
                }

            } while (currentFilePosition < exeFile.Length);

            Thread.Sleep(1000);

            var response = transporter.SendRequest<ExecuteProcessRequest, ExecuteProcessResponse>(new ExecuteProcessRequest()
            {
                UploadID = uploadResponse.UploadID,
                FileName = executeFileName,
            }, TimeSpan.FromSeconds(30)).Result.Message;

            Thread.Sleep(5000);

            transporter.SendRequest<KillProcessRequest, KillProcessResponse>(new KillProcessRequest()
            {
                ProcessID = response.ProcessID,
            }).Wait();

            transporter.Disconnect().Wait();

            runner.Kill();
        }
    }
}
>if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { if (this != &from) InternalSwap(&from); } else { CopyFrom(from); } return *this; } #endif static const ::google::protobuf::Descriptor* descriptor(); static const StubMotorEncoderRequest& default_instance(); static inline const StubMotorEncoderRequest* internal_default_instance() { return reinterpret_cast<const StubMotorEncoderRequest*>( &_StubMotorEncoderRequest_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = 0; void Swap(StubMotorEncoderRequest* other); friend void swap(StubMotorEncoderRequest& a, StubMotorEncoderRequest& b) { a.Swap(&b); } // implements Message ---------------------------------------------- inline StubMotorEncoderRequest* New() const PROTOBUF_FINAL { return New(NULL); } StubMotorEncoderRequest* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL; void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; void CopyFrom(const StubMotorEncoderRequest& from); void MergeFrom(const StubMotorEncoderRequest& from); void Clear() PROTOBUF_FINAL; bool IsInitialized() const PROTOBUF_FINAL; size_t ByteSizeLong() const PROTOBUF_FINAL; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL; void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); void SharedDtor(); void SetCachedSize(int size) const PROTOBUF_FINAL; void InternalSwap(StubMotorEncoderRequest* other); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return NULL; } inline void* MaybeArenaPtr() const { return NULL; } public: ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; // nested types ---------------------------------------------------- // accessors ------------------------------------------------------- // uint32 MotorId = 1; void clear_motorid(); static const int kMotorIdFieldNumber = 1; ::google::protobuf::uint32 motorid() const; void set_motorid(::google::protobuf::uint32 value); // bool ReadEncSpeed = 2; void clear_readencspeed(); static const int kReadEncSpeedFieldNumber = 2; bool readencspeed() const; void set_readencspeed(bool value); // bool ReadDirection = 3; void clear_readdirection(); static const int kReadDirectionFieldNumber = 3; bool readdirection() const; void set_readdirection(bool value); // bool Motion_Control = 4; void clear_motion_control(); static const int kMotionControlFieldNumber = 4; bool motion_control() const; void set_motion_control(bool value); // @@protoc_insertion_point(class_scope:Tango.PMR.Stubs.StubMotorEncoderRequest) private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::uint32 motorid_; bool readencspeed_; bool readdirection_; bool motion_control_; mutable int _cached_size_; friend struct protobuf_StubMotorEncoderRequest_2eproto::TableStruct; }; // =================================================================== // =================================================================== #if !PROTOBUF_INLINE_NOT_IN_HEADERS #ifdef __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif // __GNUC__ // StubMotorEncoderRequest // uint32 MotorId = 1; inline void StubMotorEncoderRequest::clear_motorid() { motorid_ = 0u; } inline ::google::protobuf::uint32 StubMotorEncoderRequest::motorid() const { // @@protoc_insertion_point(field_get:Tango.PMR.Stubs.StubMotorEncoderRequest.MotorId) return motorid_; } inline void StubMotorEncoderRequest::set_motorid(::google::protobuf::uint32 value) { motorid_ = value; // @@protoc_insertion_point(field_set:Tango.PMR.Stubs.StubMotorEncoderRequest.MotorId) } // bool ReadEncSpeed = 2; inline void StubMotorEncoderRequest::clear_readencspeed() { readencspeed_ = false; } inline bool StubMotorEncoderRequest::readencspeed() const { // @@protoc_insertion_point(field_get:Tango.PMR.Stubs.StubMotorEncoderRequest.ReadEncSpeed) return readencspeed_; } inline void StubMotorEncoderRequest::set_readencspeed(bool value) { readencspeed_ = value; // @@protoc_insertion_point(field_set:Tango.PMR.Stubs.StubMotorEncoderRequest.ReadEncSpeed) } // bool ReadDirection = 3; inline void StubMotorEncoderRequest::clear_readdirection() { readdirection_ = false; } inline bool StubMotorEncoderRequest::readdirection() const { // @@protoc_insertion_point(field_get:Tango.PMR.Stubs.StubMotorEncoderRequest.ReadDirection) return readdirection_; } inline void StubMotorEncoderRequest::set_readdirection(bool value) { readdirection_ = value; // @@protoc_insertion_point(field_set:Tango.PMR.Stubs.StubMotorEncoderRequest.ReadDirection) } // bool Motion_Control = 4; inline void StubMotorEncoderRequest::clear_motion_control() { motion_control_ = false; } inline bool StubMotorEncoderRequest::motion_control() const { // @@protoc_insertion_point(field_get:Tango.PMR.Stubs.StubMotorEncoderRequest.Motion_Control) return motion_control_; } inline void StubMotorEncoderRequest::set_motion_control(bool value) { motion_control_ = value; // @@protoc_insertion_point(field_set:Tango.PMR.Stubs.StubMotorEncoderRequest.Motion_Control) } #ifdef __GNUC__ #pragma GCC diagnostic pop #endif // __GNUC__ #endif // !PROTOBUF_INLINE_NOT_IN_HEADERS // @@protoc_insertion_point(namespace_scope) } // namespace Stubs } // namespace PMR } // namespace Tango // @@protoc_insertion_point(global_scope) #endif // PROTOBUF_StubMotorEncoderRequest_2eproto__INCLUDED