Skip to content

Commit

Permalink
feature [windowslib]: add GetProcessTimes to the ProcessThreadsApi (
Browse files Browse the repository at this point in the history
  • Loading branch information
iRevive authored Aug 28, 2024
1 parent 4f70725 commit 7948b7b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.scalanative.testsuite.windowslib

import org.junit.Test
import org.junit.Assert._

import scala.scalanative.meta.LinktimeInfo.isWindows
import scala.scalanative.unsafe._
import scala.scalanative.windows.MinWinBaseApi.FileTimeStruct
import scala.scalanative.windows.MinWinBaseApiOps._
import scala.scalanative.windows.ProcessThreadsApi

class ProcessThreadsApiTest {

@Test def testGetProcessTimes(): Unit = if (isWindows) {
val creationTime = stackalloc[FileTimeStruct]()
val exitTime = stackalloc[FileTimeStruct]()
val kernelTime = stackalloc[FileTimeStruct]()
val userTime = stackalloc[FileTimeStruct]()

val result = ProcessThreadsApi.GetProcessTimes(
ProcessThreadsApi.GetCurrentProcess(),
creationTime,
exitTime,
kernelTime,
userTime
)

assertTrue("result is false", result)

assertTrue(
s"kernelTime [${kernelTime.fileTime}] < 0",
kernelTime.fileTime.toLong >= 0L
)

assertTrue(
s"userTime [${userTime.fileTime}] < 0",
userTime.fileTime.toLong >= 0L
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package scala.scalanative.windows
import scala.scalanative.unsafe.{Word => _, _}
import scalanative.unsigned._
import HandleApi.Handle
import MinWinBaseApi.FileTimeStruct
import WinBaseApi.SecurityAttributes

@link("advapi32")
Expand Down Expand Up @@ -59,6 +60,15 @@ object ProcessThreadsApi {
extern

def GetProcessId(handle: Handle): DWord = extern

def GetProcessTimes(
handle: Handle,
creationTime: Ptr[FileTimeStruct],
exitTime: Ptr[FileTimeStruct],
kernelTime: Ptr[FileTimeStruct],
userTime: Ptr[FileTimeStruct]
): Boolean = extern

def OpenThreadToken(
thread: Handle,
desiredAccess: DWord,
Expand Down

0 comments on commit 7948b7b

Please sign in to comment.