From 9fbcf76d088740aacf535e6482f86c833cfae871 Mon Sep 17 00:00:00 2001 From: HÃ¥vard Pettersen Date: Wed, 6 Apr 2022 12:18:08 +0000 Subject: remove FastOS_Application fixup (per application): - maybe ignore SIGPIPE - wire argc/argv untangle Vespa Test Framework strip down deprecated TestApp --- fastos/src/tests/coretest.cpp | 68 ------------ fastos/src/tests/tests.h | 17 ++- fastos/src/tests/typetest.cpp | 1 - fastos/src/vespa/fastos/CMakeLists.txt | 2 - fastos/src/vespa/fastos/app.cpp | 59 ---------- fastos/src/vespa/fastos/app.h | 193 --------------------------------- fastos/src/vespa/fastos/thread.h | 14 --- fastos/src/vespa/fastos/unix_app.cpp | 50 --------- fastos/src/vespa/fastos/unix_app.h | 29 ----- 9 files changed, 15 insertions(+), 418 deletions(-) delete mode 100644 fastos/src/tests/coretest.cpp delete mode 100644 fastos/src/vespa/fastos/app.cpp delete mode 100644 fastos/src/vespa/fastos/app.h delete mode 100644 fastos/src/vespa/fastos/unix_app.cpp delete mode 100644 fastos/src/vespa/fastos/unix_app.h (limited to 'fastos') diff --git a/fastos/src/tests/coretest.cpp b/fastos/src/tests/coretest.cpp deleted file mode 100644 index 01742791c58..00000000000 --- a/fastos/src/tests/coretest.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - - - - -static void -bomb(void) -{ - char *p; - - p = nullptr; - *p = 4; -} - -class FastS_Bomber : public FastOS_Runnable -{ - void Run(FastOS_ThreadInterface *thread, void *arg) - { - (void) thread; - (void) arg; - bomb(); - } -}; - -static int -bombMain(void) -{ - FastOS_ThreadPool *pool = new FastOS_ThreadPool(128*1024); - FastS_Bomber bomber; - FastOS_ThreadInterface *thread; - - thread = pool->NewThread(&bomber, nullptr); - if (thread != nullptr) - thread->Join(); - - pool->Close(); - delete pool; - return (0); -} - - -class FastS_CoreTestApp : public FastOS_Application -{ -public: - FastS_CoreTestApp(void) { } - ~FastS_CoreTestApp(void) { } - int Main(void); -}; - - -int -FastS_CoreTestApp::Main(void) -{ - - return bombMain(); -} - - -int -main(int argc, char **argv) -{ - FastS_CoreTestApp app; - setvbuf(stdout, nullptr, _IOLBF, 8192); - if (argc == 1) - return app.Entry(argc, argv); - else - return bombMain(); -} diff --git a/fastos/src/tests/tests.h b/fastos/src/tests/tests.h index e93081eaa53..3a6f2ef9010 100644 --- a/fastos/src/tests/tests.h +++ b/fastos/src/tests/tests.h @@ -1,10 +1,10 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include #include #include +#include -class BaseTest : public FastOS_Application +class BaseTest { private: BaseTest(const BaseTest&); @@ -13,17 +13,30 @@ private: int totallen; bool _allOkFlag; public: + int _argc; + char **_argv; + const char *okString; const char *failString; BaseTest () : totallen(70), _allOkFlag(true), + _argc(0), + _argv(nullptr), okString("SUCCESS"), failString("FAILURE") { } + virtual int Main() = 0; + + int Entry(int argc, char **argv) { + _argc = argc; + _argv = argv; + return Main(); + } + virtual ~BaseTest() {}; bool allWasOk() const { return _allOkFlag; } diff --git a/fastos/src/tests/typetest.cpp b/fastos/src/tests/typetest.cpp index ee7f88026bc..e5d7e9ceb74 100644 --- a/fastos/src/tests/typetest.cpp +++ b/fastos/src/tests/typetest.cpp @@ -11,7 +11,6 @@ private: { TestHeader("Object Sizes (bytes)"); - Progress(true, "FastOS_Application: %d", sizeof(FastOS_Application)); Progress(true, "FastOS_DirectoryScan %d", sizeof(FastOS_DirectoryScan)); Progress(true, "FastOS_File: %d", sizeof(FastOS_File)); Progress(true, "FastOS_Runnable %d", sizeof(FastOS_Runnable)); diff --git a/fastos/src/vespa/fastos/CMakeLists.txt b/fastos/src/vespa/fastos/CMakeLists.txt index 605b1e40a38..e4274261951 100644 --- a/fastos/src/vespa/fastos/CMakeLists.txt +++ b/fastos/src/vespa/fastos/CMakeLists.txt @@ -1,13 +1,11 @@ # Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. vespa_add_library(fastos_objects OBJECT SOURCES - app.cpp backtrace.c file.cpp file_rw_ops.cpp linux_file.cpp thread.cpp - unix_app.cpp unix_file.cpp unix_thread.cpp ) diff --git a/fastos/src/vespa/fastos/app.cpp b/fastos/src/vespa/fastos/app.cpp deleted file mode 100644 index 8477f79f00d..00000000000 --- a/fastos/src/vespa/fastos/app.cpp +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -//************************************************************************ -/** - * Implementation of FastOS_ApplicationInterface methods. - * - * @author Div, Oivind H. Danielsen - */ - -#include "app.h" -#include "file.h" -#include "thread.h" -#include -#include - -FastOS_ApplicationInterface::FastOS_ApplicationInterface() : - _argc(0), - _argv(nullptr) -{ -} - -FastOS_ApplicationInterface::~FastOS_ApplicationInterface () = default; - -bool FastOS_ApplicationInterface::Init () -{ - bool rc=false; - - if (PreThreadInit()) { - if (FastOS_Thread::InitializeClass()) { - rc = true; - } else { - fprintf(stderr, "FastOS_Thread class initialization failed.\n"); - } - } else - fprintf(stderr, "FastOS_PreThreadInit failed.\n"); - - return rc; -} - - -void FastOS_ApplicationInterface::Cleanup () -{ - FastOS_Thread::CleanupClass(); -} - -int FastOS_ApplicationInterface::Entry (int argc, char **argv) -{ - int rc=255; - - _argc = argc; - _argv = argv; - - if (Init()) { - rc = Main(); - } - - Cleanup(); - - return rc; -} diff --git a/fastos/src/vespa/fastos/app.h b/fastos/src/vespa/fastos/app.h deleted file mode 100644 index c03dbc5848c..00000000000 --- a/fastos/src/vespa/fastos/app.h +++ /dev/null @@ -1,193 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -//************************************************************************ -/** - * @file - * Class definition for FastOS_ApplicationInterface. - * - * @author Div, Oivind H. Danielsen - */ - -#pragma once - - -#include "types.h" - -/** - * FastOS application wrapper class. - * This class manages initialization and cleanup of the services - * provided by FastOS. - * Your application should inherit from this class, and implement - * @ref Main(). - * It is possible, but not required to override the @ref Init() - * and @ref Cleanup() methods. If you do, make sure you invoke - * the superclass, in order to perform the neccessary initialization - * and cleanup. - * - * To startup the FastOS_Application, invoke @ref Entry() as shown - * in the example below. This will call @ref Init(), @ref Main() - * (if @ref Init() succeeds) and @ref Cleanup(), in that order. - * - * Example: - * @code - * #include - * - * class MyApplication : public FastOS_Application - * { - * int Main () - * { - * printf("Hello world\n"); - * - * return 0; - * } - * }; - * - * - * int main (int argc, char **argv) - * { - * MyApplication app; - * - * app.Entry(argc, argv); - * } - * @endcode - * - * Here is another example. This version overrides @ref Init() and - * @ref Cleanup(). Most applications do not need to do this, but - * an example of how to do it is included anyway: - * @code - * #include - * - * class MyApplication : public FastOS_Application - * { - * bool MyOwnInitializationStuff () - * { - * printf("My initialization stuff\n"); - * return true; - * } - * - * void MyOwnCleanupStuff() - * { - * printf("My cleanup stuff\n"); - * } - * - * // Most applications do not need to override this method. - * // If you do, make sure you invoke the superclass Init() - * // first. - * bool Init () - * { - * bool rc=false; - * - * if(FastOS_Application::Init()) - * { - * if(MyOwnInitializationStuff()) - * { - * rc = true; - * } - * } - * - * // The application will not start if false is returned. - * return rc; - * } - * - * // Most applications do not need to override this method. - * // If you do, make sure you invoke the superclass Cleanup() - * // at the end. - * // Note that Cleanup() is always invoked, even when Init() - * // fails. - * void Cleanup () - * { - * MyOwnCleanupStuff(); - * - * FastOS_Application::Cleanup(); - * } - * - * int Main () - * { - * printf("Hello world\n"); - * - * return 0; - * } - * }; - * - * - * int main (int argc, char **argv) - * { - * MyApplication app; - * - * app.Entry(argc, argv); - * } - * - * @endcode - */ -class FastOS_ApplicationInterface -{ - friend int main (int argc, char **argv); -protected: - virtual bool PreThreadInit () { return true; } - -public: - int _argc; - char **_argv; - - FastOS_ApplicationInterface(); - FastOS_ApplicationInterface(const FastOS_ApplicationInterface&) = delete; - FastOS_ApplicationInterface& operator=(const FastOS_ApplicationInterface&) = delete; - virtual ~FastOS_ApplicationInterface(); - - /** - * FastOS initialization. - * This method performs the neccessary initialization for FastOS. - * It is possible to override this method, see the class documentation - * for an example. - * @ref Main() will be called, if and only if @ref Init() returns true. - * @ref Cleanup will always be called, regardless of the @ref Init() - * return value. - */ - virtual bool Init(); - - /** - * FastOS Entry. - * This method is used to enter the application and provide command - * line arguments. See the class documentation for an example on - * how this is used. - * @param argc Number of arguments - * @param argv Array of arguments - * @return Errorlevel returned to the shell - */ - int Entry (int argc, char **argv); - - /** - * FastOS Main. - * This is where your application starts. See the class documentation - * for an example on how this is used. - * @return Errorlevel returned to the shell - */ - virtual int Main ()=0; - - /** - * FastOS Cleanup. - * This method performs the neccessary cleanup for FastOS. - * It is possible to override this method, see the class documentation - * for an example. - * @ref Cleanup() is always called, regardless of the return values - * of @ref Init() and @ref Main(). - */ - virtual void Cleanup (); -}; - - -#include -typedef FastOS_UNIX_Application FASTOS_PREFIX(Application); - - - -// Macro included for convenience. -#define FASTOS_MAIN(application_class) \ -int main (int argc, char **argv) \ -{ \ - application_class app; \ - \ - return app.Entry(argc, argv); \ -} - - - diff --git a/fastos/src/vespa/fastos/thread.h b/fastos/src/vespa/fastos/thread.h index f881095c29a..b3627d99d31 100644 --- a/fastos/src/vespa/fastos/thread.h +++ b/fastos/src/vespa/fastos/thread.h @@ -317,20 +317,6 @@ protected: bool _runningFlag; public: - /** - * Initialize the thread class. This is invoked by - * @ref FastOS_Application::Init(). - * @return Boolean success/failure - */ - static bool InitializeClass () {return true;}; - - /** - * Cleanup the thread class. This is invoked by - * @ref FastOS_Application::Cleanup(). - * @return Boolean success/failure - */ - static bool CleanupClass () {return true;}; - /** * Constructor. Resets internal attributes. */ diff --git a/fastos/src/vespa/fastos/unix_app.cpp b/fastos/src/vespa/fastos/unix_app.cpp deleted file mode 100644 index 733b8806fb5..00000000000 --- a/fastos/src/vespa/fastos/unix_app.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -/** -****************************************************************************** -* @author Oivind H. Danielsen -* @date Creation date: 2000-01-18 -* @file -* Implementation of FastOS_UNIX_Application methods. -*****************************************************************************/ - -#include "app.h" -#include "time.h" -#include -#include -#include - - -FastOS_UNIX_Application::FastOS_UNIX_Application() = default; -FastOS_UNIX_Application::~FastOS_UNIX_Application() = default; - -extern "C" -{ -extern char **environ; -}; - -bool FastOS_UNIX_Application::PreThreadInit () -{ - bool rc = true; - if (FastOS_ApplicationInterface::PreThreadInit()) { - // Ignore SIGPIPE - struct sigaction act; - act.sa_handler = SIG_IGN; - sigemptyset(&act.sa_mask); - act.sa_flags = 0; - sigaction(SIGPIPE, &act, nullptr); - } else { - rc = false; - fprintf(stderr, "FastOS_ApplicationInterface::PreThreadInit failed\n"); - } - return rc; -} - -bool FastOS_UNIX_Application::Init () -{ - return FastOS_ApplicationInterface::Init(); -} - -void FastOS_UNIX_Application::Cleanup () -{ - FastOS_ApplicationInterface::Cleanup(); -} diff --git a/fastos/src/vespa/fastos/unix_app.h b/fastos/src/vespa/fastos/unix_app.h deleted file mode 100644 index 0f11356614e..00000000000 --- a/fastos/src/vespa/fastos/unix_app.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -//************************************************************************ -/** - * Class definitions for FastOS_UNIX_Application. - * - * @author Div, Oivind H. Danielsen - */ - -#pragma once - -#include "app.h" -#include "types.h" -#include - -/** - * This is the generic UNIX implementation of @ref FastOS_ApplicationInterface - */ -class FastOS_UNIX_Application : public FastOS_ApplicationInterface -{ -protected: - bool PreThreadInit () override; -public: - FastOS_UNIX_Application (); - FastOS_UNIX_Application(const FastOS_UNIX_Application&) = delete; - FastOS_UNIX_Application& operator=(const FastOS_UNIX_Application&) = delete; - virtual ~FastOS_UNIX_Application(); - bool Init () override; - void Cleanup () override; -}; -- cgit v1.2.3