Boost logo

Boost Test Library: Execution Monitor

Introduction
Benefits
Specifications
Compilation
Examples
Rationale
Design

Introduction

Boost Test Library のExecution Monitor はユーザの作成した関数を呼出し、面倒なエラー検出からユーザを解放す るものである。Execution Monitor を使用するには boost::execution_monitorから派 生したクラスを作成し、int execution_monitor::function()をオーバー ライトする。モニター関数を開始するには、 execution_monitor::execute( timeout )メンバ関数を呼び出す。Execution Monitor の実装において、すべてのシンボルはネームスペースboost以下 に配置されている。reference to the top

Benefits

エラー探知関数を決められた方法で実行し、統一形式でエラーを通知する。

Specification of boost::execution_monitor

boost::execution_monitor はいくつかの種 類のシグナルや例外を、統一的に検知・報告し、種々のエラーをboost::execution_exceptionに変換して呼び出し側に返す。

Usage:

  1. execution_monitorから派生したク ラスを作成する。
  2. 仮想関数であるint execution_monitor::function()をオーバーライトする。
  3. execution_monitor::execute( timeout )を呼び出す. timeout 引数で指定し た時間(秒)後にtimer_error 例外が発生する。プラットフォームによっては無視される場合がある。

Effects:

try/catchブロック内にて execution_monitor::function()を呼び出しを行うのだが、この関数が詳細 のわからない、プラットフォーム依存のエラー検知コードを含む場合がある。 キャッチされていない例外、ハードウェアまたはソフトウェアシグナル、そ の他の例外が発生した場合には、boost::execution_exceptionを発 生する。 execution_monitor::execute() は the execution_monitor::function()がエラーとして非ゼロ値を返すことを想定していない。

Returns:

execution_monitor::function()が返す整数値。

reference to the top

Specification of boost::execution_exception

enum execution_exception {
public:
    enum error_code {
        cpp_exception_error,    // note (1) を見よ
        system_error,           // note (2) を見よ
        timeout_error,          // いくつかのプラットフォームのみ検出可能
        user_fatal_error,       // ユーザによって報告された致命的エラー
        system_fatal_error      // note (2) を見よ
    };

    error_code code() const;
    char const what() const;
};

Note 1: キャッチされていないC++例外のみがエラーとして扱われる。 アプリケーション内で例外をキャッチしている場合、その例外は boost::execution_monitorには到 達しない。

Note 2: これらのエラーは、UNIXシグナルまたはWindows構造化例外を含む。 これらの多くはハードウェアトラップが原因で起きる。

何がfatal_system_exceptionで何が単なる system_exceptionであるかは実装次第である。 致命的エラーが起きるの は、実行を継続するのが不適当であるスタックオーバーフローやアドレッ シング例外など、マシンが破損状態である場合が多い。 reference to the top

The Execution Monitor compilation

Execution Monitorを単独で使用するときには、 プロジェクトにexecution_monitor.cppをイ ンクルードする。これは他のすべてのBoost Test Library コンポーネ ントの一部として提供されている。

Examples

Execution Monitor を使用した例については Program Execution Monitorまたは Unit Test Frameworkを見よ。

Rationale

関数を呼び出す際、その関数がユーザまた はシステム例外を発生していないことを確認しなければならない場合はよく ある。また、統一形式での例外の報告もうってつけであろう。 設計時には常に、使用できるメモリが全くない、またはほとんどない状態になり得ることに気をつけるべきであろう。

Design

Boost Test Library Designドキュメントでは、Execution Monitorとその他のコンポーネントとの関連性について述べている。reference to the top