<commit_before>/*
 * This software is licensed under the GNU Affero General Public License, quoted below.
 *
 * This file is a part of PowerAPI.
 *
 * Copyright (C) 2011-2014 Inria, University of Lille 1.
 *
 * PowerAPI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 *
 * PowerAPI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with PowerAPI.
 *
 * If not, please consult http://www.gnu.org/licenses/agpl-3.0.html.
 */
package org.powerapi.module.powerspy

import java.util.UUID

import akka.actor.{Actor, Props, ActorSystem}
import akka.testkit.{TestActorRef, TestKit}
import akka.util.Timeout
import org.powerapi.UnitTest
import org.powerapi.core.{OSHelper, MessageBus}
import scala.concurrent.duration.DurationInt

class PSpyDataListener(eventBus: MessageBus, muid: UUID) extends Actor {
  import PSpyMetricsChannel.{PSpyDataReport, subscribePSpyAllDataReport, subscribePSpyRatioDataReport}

  override def preStart(): Unit = {
    subscribePSpyAllDataReport(eventBus)(self)
    subscribePSpyRatioDataReport(eventBus)(self)
  }

  def receive() = {
    case msg: PSpyDataReport => println(msg)
  }
}

class PowerSpySensorMock(eventBus: MessageBus, osHelper: OSHelper, timeout: Timeout)
  extends PowerSpySensor(eventBus, osHelper, timeout) {

  override lazy val sppUrl = "btspp://000BCE071E9B:1;authenticate=false;encrypt=false;master=false"
  override lazy val version = PowerSpyVersion.POWERSPY_V1
}

class OSHelperMock extends OSHelper {
  import org.powerapi.core.{Application, Process, Thread, Target, TargetUsageRatio, TimeInStates}

  def getProcesses(application: Application): List[Process] = {
    application match {
      case Application("app") => List(Process(2), Process(3))
    }
  }

  def getThreads(process: Process): List[Thread] = List()

  def getProcessCpuTime(process: Process): Option[Long] = {
    process match {
      case Process(2) => Some(10 + 5)
      case Process(3) => Some(3 + 5)
      case _ => None
    }
  }

  def getGlobalCpuTime(): Option[Long] = Some(43171 + 1 + 24917 + 25883594 + 1160 + 19 + 1477 + 0)

  def getTimeInStates(): TimeInStates = TimeInStates(Map())
}

class PowerSpySensorSuite(system: ActorSystem) extends UnitTest(system) {
  import PSpyMetricsChannel.PSpyChildMessage
<commit_msg>refactor: remove useless imports<commit_after>/*
 * This software is licensed under the GNU Affero General Public License, quoted below.
 *
 * This file is a part of PowerAPI.
 *
 * Copyright (C) 2011-2014 Inria, University of Lille 1.
 *
 * PowerAPI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 *
 * PowerAPI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with PowerAPI.
 *
 * If not, please consult http://www.gnu.org/licenses/agpl-3.0.html.
 */
package org.powerapi.module.powerspy

import java.util.UUID

import akka.actor.{Actor, Props, ActorSystem}
import akka.testkit.{TestActorRef, TestKit}
import akka.util.Timeout
import org.powerapi.UnitTest
import org.powerapi.core.{OSHelper, MessageBus}
import scala.concurrent.duration.DurationInt

class PSpyDataListener(eventBus: MessageBus, muid: UUID) extends Actor {
  import PSpyMetricsChannel.{PSpyDataReport, subscribePSpyAllDataReport, subscribePSpyRatioDataReport}

  override def preStart(): Unit = {
    subscribePSpyAllDataReport(eventBus)(self)
    subscribePSpyRatioDataReport(eventBus)(self)
  }

  def receive() = {
    case msg: PSpyDataReport => println(msg)
  }
}

class PowerSpySensorMock(eventBus: MessageBus, osHelper: OSHelper, timeout: Timeout)
  extends PowerSpySensor(eventBus, osHelper, timeout) {

  override lazy val sppUrl = "btspp://000BCE071E9B:1;authenticate=false;encrypt=false;master=false"
  override lazy val version = PowerSpyVersion.POWERSPY_V1
}

class OSHelperMock extends OSHelper {
  import org.powerapi.core.{Application, Process, Thread, TimeInStates}

  def getProcesses(application: Application): List[Process] = {
    application match {
      case Application("app") => List(Process(2), Process(3))
    }
  }

  def getThreads(process: Process): List[Thread] = List()

  def getProcessCpuTime(process: Process): Option[Long] = {
    process match {
      case Process(2) => Some(10 + 5)
      case Process(3) => Some(3 + 5)
      case _ => None
    }
  }

  def getGlobalCpuTime(): Option[Long] = Some(43171 + 1 + 24917 + 25883594 + 1160 + 19 + 1477 + 0)

  def getTimeInStates(): TimeInStates = TimeInStates(Map())
}

class PowerSpySensorSuite(system: ActorSystem) extends UnitTest(system) {
  import PSpyMetricsChannel.PSpyChildMessage

{'fraction_non_alphanumeric': 0.0933529736696741, 'fraction_numerical': 0.022095378383354815, 'mean_word_length': 4.531568228105907, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '1566210', 'n_tokens_mistral': 1718, 'n_tokens_neox': 1629, 'n_words': 515}