<commit_before># SPDX-License-Identifier: Apache-2.0
#
# Copyright (C) 2015, 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.
#

import datetime
import json
import logging
import os
import re
import shutil
import sys
import time
import unittest

import devlib

from wlgen import RTA
from energy import EnergyMeter
from conf import JsonConf

from devlib.utils.misc import memoized
from trappy.stats.Topology import Topology

from devlib import Platform

USERNAME_DEFAULT = 'root'
PASSWORD_DEFAULT = ''
WORKING_DIR_DEFAULT = '/data/local/schedtest'
FTRACE_EVENTS_DEFAULT = ['sched:*']
FTRACE_BUFSIZE_DEFAULT = 10240
OUT_PREFIX = 'results'
LATEST_LINK = 'results_latest'

basepath = os.path.dirname(os.path.realpath(__file__))
basepath = basepath.replace('/libs/utils', '')

class ShareState(object):
    __shared_state = {}

    def __init__(self):
        self.__dict__ = self.__shared_state

class TestEnv(ShareState):

    _initialized = False

    def __init__(self, target_conf=None, test_conf=None, wipe=True,
                 force_new=False):
        """
        Initialize the LISA test environment.

        The test environment is defined by:
        - a target configuration (target_conf) defining which HW platform we
        want to use to run the experiments
        - a test configuration (test_conf) defining which SW setups we need on
        that HW target
        - a folder to collect the experiments results, which can be specified
        using the test_conf::results_dir option and is by default wiped from
        all the previous contents (if wipe=True)

        :param target_conf: the HW target we want to use
        :type target_conf: dict

        :param test_conf: the SW setup of the HW target in use
        :type test_conf: dict

        :param wipe: set true to cleanup all previous content from the output
        folder
        :type wipe: bool

        :param force_new: Create a new TestEnv object even if there is
        one available for this session.  By default, TestEnv only
        creates one object per session, use this to override this
        behaviour.
        :type force_new: bool
        """
        super(TestEnv, self).__init__()

        if self._initialized and not force_new:
            return

        self.conf = None
        self.test_conf = None
        self.res_dir = None
        self.target = None
        self.ftrace = None
        self.workdir = WORKING_DIR_DEFAULT
        self.__tools = []
        self.__installed_tools = set()
        self.__modules = []
        self.__connection_settings = None
        self._calib = None

        # Keep track of target IP and MAC address
        self.ip = None
        self.mac = None

        # Keep track of last installed kernel
        self.kernel = None
        self.dtb = None

        # Energy meter configuration
        self.emeter = None

        # The platform descriptor to be saved into the results folder
        self.platform = {}
<commit_msg>TestEnv: Make sure self.conf and self.test_conf aren't None<commit_after># SPDX-License-Identifier: Apache-2.0
#
# Copyright (C) 2015, 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.
#

import datetime
import json
import logging
import os
import re
import shutil
import sys
import time
import unittest

import devlib

from wlgen import RTA
from energy import EnergyMeter
from conf import JsonConf

from devlib.utils.misc import memoized
from trappy.stats.Topology import Topology

from devlib import Platform

USERNAME_DEFAULT = 'root'
PASSWORD_DEFAULT = ''
WORKING_DIR_DEFAULT = '/data/local/schedtest'
FTRACE_EVENTS_DEFAULT = ['sched:*']
FTRACE_BUFSIZE_DEFAULT = 10240
OUT_PREFIX = 'results'
LATEST_LINK = 'results_latest'

basepath = os.path.dirname(os.path.realpath(__file__))
basepath = basepath.replace('/libs/utils', '')

class ShareState(object):
    __shared_state = {}

    def __init__(self):
        self.__dict__ = self.__shared_state

class TestEnv(ShareState):

    _initialized = False

    def __init__(self, target_conf=None, test_conf=None, wipe=True,
                 force_new=False):
        """
        Initialize the LISA test environment.

        The test environment is defined by:
        - a target configuration (target_conf) defining which HW platform we
        want to use to run the experiments
        - a test configuration (test_conf) defining which SW setups we need on
        that HW target
        - a folder to collect the experiments results, which can be specified
        using the test_conf::results_dir option and is by default wiped from
        all the previous contents (if wipe=True)

        :param target_conf: the HW target we want to use
        :type target_conf: dict

        :param test_conf: the SW setup of the HW target in use
        :type test_conf: dict

        :param wipe: set true to cleanup all previous content from the output
        folder
        :type wipe: bool

        :param force_new: Create a new TestEnv object even if there is
        one available for this session.  By default, TestEnv only
        creates one object per session, use this to override this
        behaviour.
        :type force_new: bool
        """
        super(TestEnv, self).__init__()

        if self._initialized and not force_new:
            return

        self.conf = {}
        self.test_conf = {}
        self.res_dir = None
        self.target = None
        self.ftrace = None
        self.workdir = WORKING_DIR_DEFAULT
        self.__tools = []
        self.__installed_tools = set()
        self.__modules = []
        self.__connection_settings = None
        self._calib = None

        # Keep track of target IP and MAC address
        self.ip = None
        self.mac = None

        # Keep track of last installed kernel
        self.kernel = None
        self.dtb = None

        # Energy meter configuration
        self.emeter = None

        # The platform descriptor to be saved into the results folder
        self.platform = {}

{'fraction_non_alphanumeric': 0.06492027334851937, 'fraction_numerical': 0.004271070615034169, 'mean_word_length': 2.724814422057264, 'pattern_counts': {'":': 0, '<': 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': '2594049', 'n_tokens_mistral': 1910, 'n_tokens_neox': 1844, 'n_words': 757}