Commit 5fe2bbeb authored by Greg Williams's avatar Greg Williams
Browse files

Updated to use new kinetic-ruby resident server, and ripped out old version from Rakefile.

Fixed syntax error in log file params.
Updates to try and make Doxygen generate doxygenized kinetic_api.h, but still doesn't work.
parent de532122
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ GEM
      net-http-pipeline
    highline (1.6.21)
    json (1.8.1)
    kinetic-ruby (0.2.1)
    kinetic-ruby (0.3.8)
      beefcake
      rake (>= 0.9.2.2)
      rspec
@@ -58,7 +58,7 @@ GEM
    rspec-support (3.0.3)
    slop (3.6.0)
    thor (0.19.1)
    travis (1.6.16)
    travis (1.6.17)
      addressable (~> 2.3)
      backports
      faraday (~> 0.9)
+4 −123
Original line number Diff line number Diff line
TEAMCITY_BUILD = !ENV['TEAMCITY_PROJECT_NAME'].nil?

require 'kinetic-ruby'
load 'kinetic-ruby.rake'

require 'ceedling'
Ceedling.load_project(config: './project.yml')

@@ -119,121 +122,7 @@ namespace :doxygen do

end

namespace :test_server do

  require "webrick"
  DEFAULT_KINETIC_PORT = 8123
  TEST_KINETIC_PORT = 8999
  $test_server = nil

  # WEBrick is a Ruby library that makes it easy to build an HTTP server with Ruby.
  # It comes with most installations of Ruby by default (it’s part of the standard library),
  # so you can usually create a basic web/HTTP server with only several lines of code.
  #
  # The following code creates a generic WEBrick server on the local machine on port 1234
  class KineticServlet < WEBrick::HTTPServlet::AbstractServlet
    def do_GET (request, response)
      # a = request.query["a"]
      response.status = 200
      response.content_type = "text/plain"
      response.body = "Kinetic Fake Test Server"

      case request.path
      when "/admin"
        response.body += " - admin mode"
      when "/config"
        response.body += " - config mode"
      else
        response.body += " - normal mode"
      end
    end
  end

  class KineticTestServer

    def initialize(port = DEFAULT_KINETIC_PORT)
      raise "Invalid Kinetic test server port specified (port: #{port})" if !port || port < 0
      require 'kinetic-ruby'
      @port = port
      @server = nil
      @worker = nil
      @listeners = []
    end

    def start
      return unless @server.nil?

      @server = TCPServer.new @port
      @listeners = []

      # Setup handler for signaled shutdown (via ctrl+c)
      trap("INT") do
        report "Test server: INT triggered Kintic Test Server shutdown"
        shutdown
      end

      # Create worker thread for test server to run in so we can continue
      @worker = Thread.new do
        report "Test server: Listening for Kinetic clients..."
        loop do
          @listeners << Thread.start(@server.accept) do |client|
            report "Test server: Connected to #{client.inspect}"
            request = ""
            while request += client.getc # Read characters from socket

              request_match = request.match(/^read\((\d+)\)/)
              if request_match
                len = request_match[1].to_i
                response = "G"*len
                report "Test server: Responding to 'read(#{len})' w/ '#{response}'"
                client.write response
                request = ""
              end

              if request =~ /^readProto()/
                kruby = KineticRuby.new
                response = kruby.encode_test_message
                report "Test server: Responding to 'read(#{len})' w/ dummy protobuf (#{response.length} bytes)"
                client.write response
                request = ""
              end
            end
            # report "Test server: Client #{client.inspect} disconnected!"
          end
        end
      end

    end

    def shutdown
      return if @server.nil?
      report_banner "Test server: Kinetic Test Server shutting down..."
      @listeners.each do |client|
        client.join(0.3) if client.alive?
      end
      @listeners = []
      @worker.exit
      @worker = nil
      @server.close
      @server = nil
      report "Test server: Kinetic Test Server shutdown complete"
    end

  end

  task :start do
    $test_server ||= KineticTestServer.new(DEFAULT_KINETIC_PORT)
    $test_server.start
  end

  task :shutdown do
    $test_server.shutdown unless $test_server.nil?
    $test_server = nil
  end

end

task 'test/integration/test_kinetic_socket.c' => ['test_server:start']
task 'test/integration/test_kinetic_socket.c' => ['server:start']

desc "Run client test utility"
task :run do
@@ -292,11 +181,3 @@ task :ci => [
  # 'verbose', # uncomment to enable verbose output for CI builds
  'all'
]


# This block of code will be run prior to Rake instance terminating
END {
  # Ensure test server is shutdown, so we can terminate cleanly
  $test_server.shutdown unless $test_server.nil?
  $test_server = nil
}
+2 −2
Original line number Diff line number Diff line
@@ -24,9 +24,9 @@
#include "kinetic_logger.h"
#include <stdio.h>

void KineticApi_Init(const char* log_file)
void KineticApi_Init(const char* logFile)
{
    KineticLogger_Init(log_file);
    KineticLogger_Init(logFile);
}

bool KineticApi_Connect(
+41 −1
Original line number Diff line number Diff line
@@ -26,15 +26,39 @@
#include "kinetic_pdu.h"
#include "kinetic_operation.h"

/**
 * Initializes the Kinetic API andcsonfigures logging destination.
 *
 * @param logFile Path to log file. Specify NULL to log to STDOUT.
 */
void KineticApi_Init(
    const char* log_file);
    const char* logFile);

/**
 * @brief Establishes a Kinetic protocol socket connection to a host.
 *
 * @param connection     KineticConnection instance to configure with connection info
 * @param host           Host name or IP address to connect to
 * @param port           Port to establish socket connection on
 * @param blocking       Set to true for blocking or false for non-bloocking I/O
 * @return               Returns true if connection succeeded
 */
bool KineticApi_Connect(
    KineticConnection* connection,
    const char* host,
    int port,
    bool blocking);

/**
 * @brief Initializes and configures a Kinetic exchange.
 *
 * @param exchange   KineticExchange instance to configure with exchange info
 * @param connection KineticConnection to associate with exchange
 * @param identity   Identity to use for the exchange
 * @param key        Key to use for HMAC calculations
 * @param keyLength  Length of HMAC key
 * @return           Returns true if configuration succeeded
 */
bool KineticApi_ConfigureExchange(
    KineticExchange* exchange,
    KineticConnection* connection,
@@ -42,6 +66,16 @@ bool KineticApi_ConfigureExchange(
    uint8_t* key,
    size_t keyLength);

/**
 * @brief Creates and initializes a Kinetic operation.
 *
 * @param exchange   KineticExchange instance to populate with exchange info
 * @param request    KineticPDU instance to use for request
 * @param requestMsg KineticMessage instance to use for request
 * @param reponse    KineticPDU instance to use for reponse
 * @param reponseMsg KineticMessage instance to use for reponse
 * @return           Returns a configured operation instance
 */
KineticOperation KineticApi_CreateOperation(
    KineticExchange* exchange,
    KineticPDU* request,
@@ -49,6 +83,12 @@ KineticOperation KineticApi_CreateOperation(
    KineticPDU* response,
    KineticMessage* responseMsg);

/**
 * @brief Executes a NOOP command to test whether the Kinetic Device is operational
 *
 * @param exchange   KineticOperation instance to use for the operation
 * @return           Returns the resultant status code
 */
KineticProto_Status_StatusCode KineticApi_NoOp(
    KineticOperation* operation
    );
+3 −3
Original line number Diff line number Diff line
@@ -26,16 +26,16 @@
static char LogFile[256] = "";
bool LogToStdErr = true;

void KineticLogger_Init(const char* log_file)
void KineticLogger_Init(const char* logFile)
{
    if (log_file == NULL)
    if (logFile == NULL)
    {
        LogToStdErr = true;
    }
    else
    {
        FILE* fd;
        strcpy(LogFile, log_file);
        strcpy(LogFile, logFile);
        fd = fopen(LogFile, "w");
        fclose(fd);
        LogToStdErr = false;
Loading