<commit_before>/*
 *  This routine is the initialization task for this test program.
 *  It is called from init_exec and has the responsibility for creating
 *  and starting the tasks that make up the test.  If the time of day
 *  clock is required for the test, it should also be set to a known
 *  value by this function.
 *
 *  COPYRIGHT (c) 1994 by Division Incorporated
 *  Based in part on OAR works.
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.com/license/LICENSE.
 */

#include <bsp.h>

#include <rtems.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <rtems/shell.h>

#if !defined(BSP_SMALL_MEMORY)
#define RTEMS_TEST_IO_STREAM

static int num_inst = 0;

class A {
public:
    A(void)
    {
        num_inst++;
        printf(
          "Hey I'm in base class constructor number %d for %p.\n",
          num_inst,
          this
        );

 /*
  * Make sure we use some space
  */

        string = new char[50];
 sprintf(string, "Instantiation order %d", num_inst);
    };

    virtual ~A()
    {
        printf(
          "Hey I'm in base class destructor number %d for %p.\n",
          num_inst,
          this
        );
 print();
        num_inst--;
    };

    virtual void print()  { printf("%s\n", string); };

protected:
    char  *string;
};

class B : public A {
public:
    B(void)
    {
        num_inst++;
        printf(
          "Hey I'm in derived class constructor number %d for %p.\n",
          num_inst,
          this
        );

 /*
  * Make sure we use some space
  */

        string = new char[50];
 sprintf(string, "Instantiation order %d", num_inst);
    };

    ~B()
    {
        printf(
          "Hey I'm in derived class destructor number %d for %p.\n",
          num_inst,
          this
        );
       print();
        num_inst--;
    };

    void print()  { printf("Derived class - %s\n", string); }
};


A foo;
B foobar;

static void
cdtest(void)
{
    A bar, blech, blah;
    B bleak;

    printf("IO Stream not tested\n");

    bar = blech;

 printf( "before try block\n" );
//  try
 {
    printf("Raising this");
 }
//  catch( const char *e )
//  {
//     printf( "Got it: %s\n", e );
//  }
 printf( "catch got called, exception handling worked !!!\n" );
}
#endif


extern "C"
void* POSIX_Init(void*);

void* POSIX_Init(void*)
{
    printf( "\n\n*** CONSTRUCTOR/DESTRUCTOR TEST ***\n" );

    auto ret = rtems_shell_init("SHLL", 4096, 254, "/dev/console", true, false, NULL);

    printf("RTEMS SHELL init ret: %d\n", int(ret));

    ::sleep(1);
    printf("Work area size: %d\n", rtems_configuration_get_work_space_size());
    ::sleep(1);
    printf("Tick interval : %d\n", rtems_configuration_get_microseconds_per_tick());
    ::sleep(1);

#if !defined(BSP_SMALL_MEMORY)
    cdtest();
#endif

    printf( "*** END OF CONSTRUCTOR/DESTRUCTOR TEST ***\n\n\n" );

    for (;;)
    {
        ::sleep(1);
    }

    return NULL;
}<commit_msg>Exception tests removed, high resolution clock test added<commit_after>/*
 * Copyright (C) 2015 <NAME> <<EMAIL>>
 */


#include <bsp.h>

#include <rtems.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <rtems/shell.h>
#include <sys/time.h>
#include <chrono>
#include <string>


static std::string systime2str(const std::chrono::system_clock::time_point& tp)
{
    const auto tt = std::chrono::system_clock::to_time_t(tp);
    return std::ctime(&tt);
}

static std::string nanoseconds2str(long long nanos)
{
    (void)nanoseconds2str;
    using namespace std; // For snprintf()
    char buf[80];
    (void)snprintf(buf, sizeof(buf), "%lli.%09lli",
                   static_cast<long long>(nanos / 1000000000ULL),
                   static_cast<long long>(nanos % 1000000000ULL));
    return buf;
}

extern "C" void* POSIX_Init(void*);

void* POSIX_Init(void*)
{
    printf("\nHello world!\n");

    auto ret = rtems_shell_init("SHLL", 4096, 254, "/dev/console", true, false, NULL);

    printf("RTEMS SHELL init ret: %d\n", int(ret));

    printf("Work area size: %d\n", rtems_configuration_get_work_space_size());
    printf("Tick interval : %d\n", rtems_configuration_get_microseconds_per_tick());

    for (;;)
    {
        ::sleep(1);

        printf("system clock:    %s\n", systime2str(std::chrono::system_clock::now()).c_str());
        printf("monotonic clock: %s   %s\n",
               nanoseconds2str(std::chrono::duration_cast<std::chrono::nanoseconds>(
                   std::chrono::steady_clock::now().time_since_epoch()).count()).c_str(),
               nanoseconds2str(std::chrono::duration_cast<std::chrono::nanoseconds>(
                   std::chrono::steady_clock::now().time_since_epoch()).count()).c_str());

        auto ts = ::timespec();
        (void)::clock_gettime(CLOCK_MONOTONIC, &ts);
        printf("%u.%09li   ", unsigned(ts.tv_sec), ts.tv_nsec);
        (void)::clock_gettime(CLOCK_MONOTONIC, &ts);
        printf("%u.%09li\n", unsigned(ts.tv_sec), ts.tv_nsec);

        puts("");
    }

    return NULL;
}
{'fraction_non_alphanumeric': 0.15360378101614808, 'fraction_numerical': 0.012997243009058685, 'mean_word_length': 2.7100073046018993, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1593079', 'n_tokens_mistral': 1840, 'n_tokens_neox': 1731, 'n_words': 444}