<commit_before># SPDX-License-Identifier: Apache-2.0
#
# Copyright (C) 2016, ARM Limited and contributors.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from math import isnan

import numpy as np
import pandas as pd

from bart.common.Utils import area_under_curve

from energy_model import EnergyModelCapacityError
from perf_analysis import PerfAnalysis
from test import LisaTest, experiment_test
from trace import Trace

energy_aware_conf = {
    "tag" : "energy_aware",
    "flags" : ["ftrace", "freeze_userspace"],
    "sched_features" : "ENERGY_AWARE",
}

WORKLOAD_PERIOD_MS =  10
SET_IS_BIG_LITTLE = True
SET_INITIAL_TASK_UTIL = True

class _EnergyModelTest(LisaTest):
    """
    "Abstract" base class for generic EAS tests using the EnergyModel class

    Subclasses should provide a .workloads member to populate the 'wloads' field
    of the experiments_conf for the Executor. A set of helper methods are
    provided for making assertions about behaviour, most importantly the _test*
    methods which make assertions in a generic way.
    """

    test_conf = {
        "ftrace" : {
            "events" : [
                "sched_overutilized",
                "sched_energy_diff",
                "sched_load_avg_task",
                "sched_load_avg_cpu",
                "sched_migrate_task",
                "sched_switch"
            ],
        },
        "modules": ["cgroups"],
        "cpufreq" : {
            "governor" : "sched",
        },
    }

    negative_slack_allowed_pct = 15
    """Percentage of RT-App task activations with negative slack allowed"""

    energy_est_threshold_pct = 20
    """
    Allowed margin for error in estimated energy cost for task placement,
    compared to optimal placment.
    """

    @classmethod
    def setUpClass(cls, *args, **kwargs):
        super(_EnergyModelTest, cls).runExperiments(*args, **kwargs)

    @classmethod
    def _getExperimentsConf(cls, *args, **kwargs):
        return {
            'wloads' : cls.workloads,
            'confs' : [energy_aware_conf]
        }

    @classmethod
    def _experimentsInit(cls, *args, **kwargs):
        super(_EnergyModelTest, cls)._experimentsInit(*args, **kwargs)
<commit_msg>tests/eas/generic: Check and error if TestEnv.nrg_model not present<commit_after># SPDX-License-Identifier: Apache-2.0
#
# Copyright (C) 2016, ARM Limited and contributors.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from math import isnan

import numpy as np
import pandas as pd

from bart.common.Utils import area_under_curve

from energy_model import EnergyModel, EnergyModelCapacityError
from perf_analysis import PerfAnalysis
from test import LisaTest, experiment_test
from trace import Trace
from . import _EasTest, energy_aware_conf, WORKLOAD_PERIOD_MS
from unittest import SkipTest

energy_aware_conf = {
    "tag" : "energy_aware",
    "flags" : ["ftrace", "freeze_userspace"],
    "sched_features" : "ENERGY_AWARE",
}

WORKLOAD_PERIOD_MS =  10
SET_IS_BIG_LITTLE = True
SET_INITIAL_TASK_UTIL = True

class _EnergyModelTest(LisaTest):
    """
    "Abstract" base class for generic EAS tests using the EnergyModel class

    Subclasses should provide a .workloads member to populate the 'wloads' field
    of the experiments_conf for the Executor. A set of helper methods are
    provided for making assertions about behaviour, most importantly the _test*
    methods which make assertions in a generic way.
    """

    test_conf = {
        "ftrace" : {
            "events" : [
                "sched_overutilized",
                "sched_energy_diff",
                "sched_load_avg_task",
                "sched_load_avg_cpu",
                "sched_migrate_task",
                "sched_switch"
            ],
        },
        "modules": ["cgroups"],
        "cpufreq" : {
            "governor" : "sched",
        },
    }

    negative_slack_allowed_pct = 15
    """Percentage of RT-App task activations with negative slack allowed"""

    energy_est_threshold_pct = 20
    """
    Allowed margin for error in estimated energy cost for task placement,
    compared to optimal placment.
    """

    @classmethod
    def setUpClass(cls, *args, **kwargs):
        super(_EnergyModelTest, cls).runExperiments(*args, **kwargs)

    @classmethod
    def _getExperimentsConf(cls, test_env):
        if not test_env.nrg_model:
            try:
                test_env.nrg_model = EnergyModel.from_target(test_env.target)
            except Exception as e:
                raise SkipTest(
                    'This test requires an EnergyModel for the platform. '
                    'Either provide one manually or ensure it can be read '
                    'from the filesystem: {}'.format(e))

        return {
            'wloads' : cls.workloads,
            'confs' : [energy_aware_conf]
        }

    @classmethod
    def _experimentsInit(cls, *args, **kwargs):
        super(_EnergyModelTest, cls)._experimentsInit(*args, **kwargs)

{'fraction_non_alphanumeric': 0.08218487394957984, 'fraction_numerical': 0.005378151260504202, 'mean_word_length': 2.8693107932379713, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '7517690', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1666, 'n_words': 564}