text:
// Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.

package main

import (
	"io"
	"os"
	"testing"
	"time"

	"github.com/NVIDIA/gpu-feature-discovery/internal/resource"
	rt "github.com/NVIDIA/gpu-feature-discovery/internal/resource/testing"
	spec "github.com/NVIDIA/k8s-device-plugin/api/config/v1"
	"github.com/stretchr/testify/require"
)

func TestMigStrategyNone(t *testing.T) {
	devices := []resource.Device{
		rt.NewMigEnabledDevice(
			rt.NewMigDevice(3, 0, 20000),
			rt.NewMigDevice(3, 0, 20000),
		),
	}
	nvmlMock := rt.NewManagerMockWithDevices(devices...)
	// create VGPU mock library with empty vgpu devices
	vgpuMock := NewTestVGPUMock()

	conf := &spec.Config{
		Flags: spec.Flags{
			CommandLineFlags: spec.CommandLineFlags{
				MigStrategy:     ptr("none"),
				FailOnInitError: ptr(true),
				GFD: &spec.GFDCommandLineFlags{
					Oneshot:         ptr(true),
					OutputFile:      ptr("./gfd-test-mig-none"),
					SleepInterval:   ptr(spec.Duration(time.Second)),
					NoTimestamp:     ptr(false),
					MachineTypeFile: ptr(testMachineTypeFile),
				},
			},
		},
	}

	setupMachineFile(t)
	defer removeMachineFile(t)

	restart, err := run(nvmlMock, vgpuMock, conf, nil)
	require.NoError(t, err, "Error from run function")
	require.False(t, restart)

	outFile, err := os.Open(*conf.Flags.GFD.OutputFile)
	require.NoError(t, err, "Opening output file")

	defer func() {
		err = outFile.Close()
		require.NoError(t, err, "Closing output file")
		err = os.Remove(*conf.Flags.GFD.OutputFile)
		require.NoError(t, err, "Removing output file")
	}()

	output, err := io.ReadAll(outFile)
	require.NoError(t, err, "Reading output file")

	err = checkResult(output, cfg.Path("tests/expected-output-mig-none.txt"), false)
	require.NoError(t, err, "Checking result")

	labels, err := buildLabelMapFromOutput(output)
	require.NoError(t, err, "Building map of labels from output file")

	require.Equal(t, labels["nvidia.com/gpu.count"], "1", "Incorrect label")
	require.Equal(t, labels["nvidia.com/gpu.product"], "MOCKMODEL", "Incorrect label")
	require.Equal(t, labels["nvidia.com/gpu.memory"], "300", "Incorrect label")
}

func TestMigStrategySingleForNoMigDevices(t *testing.T) {
	nvmlMock := NewTestNvmlMock()
	// create VGPU mock library with empty vgpu devices
	vgpuMock := NewTestVGPUMock()

	conf := &spec.Config{
		Flags: spec.Flags{
			CommandLineFlags: spec.CommandLineFlags{
				MigStrategy:     ptr("single"),
				FailOnInitError: ptr(true),
				GFD: &spec.GFDCommandLineFlags{
					Oneshot:         ptr(true),
					OutputFile:      ptr("./gfd-test-mig-single-no-mig"),
					SleepInterval:   ptr(spec.Duration(time.Second)),
					NoTimestamp:     ptr(false),
					MachineTypeFile: ptr(testMachineTypeFile),
				},
			},
		},
	}

	setupMachineFile(t)
	defer removeMachineFile(t)

	restart, err := run(nvmlMock, vgpuMock, conf, nil)
	require.NoError(t, err, "Error from run function")
	require.False(t, restart)

	outFile, err := os.Open(*conf.Flags.GFD.OutputFile)
	require.NoError(t, err, "Opening output file")

	defer func() {
		err = outFile.Close()
		require.NoError(t, err, "Closing output file")
		err = os.Remove(*conf.Flags.GFD.OutputFile)
		require.NoError(t, err, "Removing output file")
	}()

	output, err := io.ReadAll(outFile)
	require.NoError(t, err, "Reading output file")

	err = checkResult(output, cfg.Path("tests/expected-output-mig-single.txt"), false)
	require.NoError(t, err, "Checking result")

	labels, err := buildLabelMapFromOutput(output)
	require.NoError(t, err, "Building map of labels from output file")

	require.Equal(t, labels["nvidia.com/mig.strategy"], "single", "Incorrect label")
	require.Equal(t, labels["nvidia.com/gpu.count"], "1", "Incorrect label")
	require.Equal(t, labels["nvidia.com/gpu.product"], "MOCKMODEL", "Incorrect label")
	require.Equal(t, labels["nvidia.com/gpu.memory"], "300", "Incorrect label")
}

func TestMigStrategySingleForMigDeviceMigDisabled(t *testing.T) {
	// create VGPU mock library with empty vgpu devices
	vgpuMock := NewTestVGPUMock()
	devices := []resource.Device{
		rt.NewDeviceMock(false).WithMigDevices(
			rt.NewMigDevice(3, 0, 20000),
			rt.NewMigDevice(3, 0, 20000),
		),
	}
	nvmlMock := rt.NewManagerMockWithDevices(devices...)

	conf := &spec.Config{
		Flags: spec.Flags{
			CommandLineFlags: spec.CommandLineFlags{
				MigStrategy:     ptr("single"),
				FailOnInitError: ptr(true),
				GFD: &spec.GFDCommandLineFlags{
					Oneshot:         ptr(true),
					OutputFile:      ptr("./gfd-test-mig-single-no-mig"),
					SleepInterval:   ptr(spec.Duration(time.Second)),
					NoTimestamp:     ptr(false),
					MachineTypeFile: ptr(testMachineTypeFile),
				},
			},
		},
	}

	setupMachineFile(t)
	defer removeMachineFile(t)

	restart, err := run(nvmlMock, vgpuMock, conf, nil)
	require.NoError(t, err, "Error from run function")
	require.False(t, restart)

	outFile, err := os.Open(*conf.Flags.GFD.OutputFile)
	require.NoError(t, err, "Opening output file")

	defer func() {
		err = outFile.Close()
		require.NoError(t, err, "Closing output file")
		err = os.Remove(*conf.Flags.GFD.OutputFile)
		require.NoError(t, err, "Removing output file")
	}()

	output, err := io.ReadAll(outFile)
	require.NoError(t, err, "Reading output file")

	err = checkResult(output, cfg.Path("tests/expected-output-mig-single.txt"), false)
	require.NoError(t, err, "Checking result")

	labels, err := buildLabelMapFromOutput(output)
	require.NoError(t, err, "Building map of labels from output file")

	require.Equal(t, labels["nvidia.com/mig.strategy"], "single", "Incorrect label")
	require.Equal(t, labels["nvidia.com/gpu.count"], "1", "Incorrect label")
	require.Equal(t, labels["nvidia.com/gpu.product"], "MOCKMODEL", "Incorrect label")
	require.Equal(t, labels["nvidia.com/gpu.memory"], "300", "Incorrect label")
}

func TestMigStrategySingle(t *testing.T) {
	// create VGPU mock library with empty vgpu devices
	vgpuMock := NewTestVGPUMock()
	devices := []resource.Device{
		rt.NewMigEnabledDevice(
			rt.NewMigDevice(3, 0, 20),
			rt.NewMigDevice(3, 0, 20),
		),
	}
	nvmlMock := rt.NewManagerMockWithDevices(devices...)

	conf := &spec.Config{
		Flags: spec.Flags{
			CommandLineFlags: spec.CommandLineFlags{
				MigStrategy:     ptr("single"),
				FailOnInitError: ptr(true),
				GFD: &spec.GFDCommandLineFlags{
					Oneshot:         ptr(true),
					OutputFile:      ptr("./gfd-test-mig-single"),
					SleepInterval:   ptr(spec.Duration(time.Second)),
					NoTimestamp:     ptr(false),
					MachineTypeFile: ptr(testMachineTypeFile),
				},
			},
		},
	}

	setupMachineFile(t)
	defer removeMachineFile(t)

	restart, err := run(nvmlMock, vgpuMock, conf, nil)
	require.NoError(t, err, "Error from run function")
	require.False(t, restart)

	outFile, err := os.Open(*conf.Flags.GFD.OutputFile)
	require.NoError(t, err, "Opening output file")

	defer func() {
		err = outFile.Close()
		require.NoError(t, err, "Closing output file")
		err = os.Remove(*conf.Flags.GFD.OutputFile)
		require.NoError(t, err, "Removing output file")
	}()

	output, err := io.ReadAll(outFile)
	require.NoError(t, err, "Reading output file")

	err = checkResult(output, cfg.Path("tests/expected-output-mig-single.txt"), false)
	require.NoError(t, err, "Checking result")

	labels, err := buildLabelMapFromOutput(output)
	require.NoError(t, err, "Building map of labels from output file")

	require.Equal(t, labels["nvidia.com/mig.strategy"], "single", "Incorrect label")
	require.Equal(t, labels["nvidia.com/gpu.count"], "2", "Incorrect label")
	require.Equal(t, labels["nvidia.com/gpu.product"], "MOCKMODEL-MIG-3g.20gb", "Incorrect label")
	require.Equal(t, labels["nvidia.com/gpu.memory"], "20", "Incorrect label")
}

func TestMigStrategyMixed(t *testing.T) {
	// create VGPU mock library with empty vgpu devices
	vgpuMock := NewTestVGPUMock()
	devices := []resource.Device{
		rt.NewMigEnabledDevice(
			rt.NewMigDevice(3, 0, 20),
			rt.NewMigDevice(1, 0, 5),
		),
	}

	nvmlMock := rt.NewManagerMockWithDevices(devices...)

	conf := &spec.Config{
		Flags: spec.Flags{
			CommandLineFlags: spec.CommandLineFlags{
				MigStrategy:     ptr("mixed"),
				FailOnInitError: ptr(true),
				GFD: &spec.GFDCommandLineFlags{
					Oneshot:         ptr(true),
					OutputFile:      ptr("./gfd-test-mig-mixed"),
					SleepInterval:   ptr(spec.Duration(time.Second)),
					NoTimestamp:     ptr(false),
					MachineTypeFile: ptr(testMachineTypeFile),
				},
			},
		},
	}

	setupMachineFile(t)
	defer removeMachineFile(t)

	restart, err := run(nvmlMock, vgpuMock, conf, nil)
	require.NoError(t, err, "Error from run function")
	require.False(t, restart)

	outFile, err := os.Open(*conf.Flags.GFD.OutputFile)
	require.NoError(t, err, "Opening output file")

	defer func() {
		err = outFile.Close()
		require.NoError(t, err, "Closing output file")
		err = os.Remove(*conf.Flags.GFD.OutputFile)
		require.NoError(t, err, "Removing output file")
	}()

	output, err := io.ReadAll(outFile)
	require.NoError(t, err, "Reading output file")

	err = checkResult(output, cfg.Path("tests/expected-output-mig-mixed.txt"), false)
	require.NoError(t, err, "Checking result")

	labels, err := buildLabelMapFromOutput(output)
	require.NoError(t, err, "Building map of labels from output file")

	require.Equal(t, labels["nvidia.com/mig.strategy"], "mixed", "Incorrect label")
	require.Equal(t, labels["nvidia.com/gpu.count"], "1", "Incorrect label")
	require.Equal(t, labels["nvidia.com/gpu.product"], "MOCKMODEL", "Incorrect label")
	require.Equal(t, labels["nvidia.com/gpu.memory"], "300", "Incorrect label")
	require.Contains(t, labels, "nvidia.com/mig-3g.20gb.count", "Missing label")
	require.Contains(t, labels, "nvidia.com/mig-1g.5gb.count", "Missing label")
}

repository: NVIDIA/gpu-feature-discovery

repo_name: NVIDIA/gpu-feature-discovery


text:
package main

import (
	"strings"
	"testing"
)

func BenchmarkStringJoin1(b *testing.B) {
	b.ReportAllocs()
	input := []string{"Hello", "World"}
	for i := 0; i < b.N; i++ {
		result := strings.Join(input, " ")
		if result != "Hello World" {
			b.Error("Unexpected result: " + result)
		}
	}
}

repository: nocai/learngo

license_type: permissive

repo_name: nocai/learngo

branch_name: refs/heads/master

extension: go


text:
Automatically generated by Mendeley Desktop 1.13.8
Any changes to this file will be lost if it is regenerated by Mendeley.

BibTeX export options can be customized via Options -> BibTeX in Mendeley Desktop

@book{DepartmentforTransport2014,
author = {DfT},
file = {:media/robin/data/Copy/1Lit/2014/DfT - 2014 - Cycling Delivery Plan Draft.pdf:pdf},
institution = {Department for Transport},
number = {October},
title = {{Cycling Delivery Plan: Draft}},
url = {https://www.gov.uk/government/uploads/system/uploads/attachment\_data/file/364791/141015\_Cycling\_Delivery\_Plan.pdf},
year = {2014}
}
@article{smoreda2013spatiotemporal,
author = {Smoreda, Zbigniew and Olteanu-Raimond, Ana-Maria and Couronn\'{e}, Thomas},
file = {:media/robin/data/Copy/1Lit/2013/Smoreda, Olteanu-Raimond, Couronn\'{e} - 2013 - Spatiotemporal data from mobile phones for personal mobility assessment.pdf:pdf},
journal = {Transport survey methods: best practice for decision making. Emerald Group Publishing, London},
title = {{Spatiotemporal data from mobile phones for personal mobility assessment}},
year = {2013}
}
@techreport{Crawford2014,
author = {Crawford, Fiona and Lovelace, Robin},
file = {:media/robin/data/Copy/1Lit/2015/Crawford, Lovelace - 2015 - The benefits of getting England cycling.pdf:pdf},
institution = {Cyclist Toring Club (CTC)},
title = {{The benefits of getting England cycling}},
url = {http://www.ctc.org.uk/news/20150120-research-shows-growth-cycling-worth-\%C2\%BC-trillion-england\%E2\%80\%99s-economy},
year = {2015}
}
@book{TransportforNSW2014,
author = {{Transport for NSW}},
file = {:media/robin/data/Copy/1Lit/2014/Transport for NSW - 2014 - Household Travel Survey Report Sydney 201213.pdf:pdf},
isbn = {9780731328680},
number = {November},
title = {{Household Travel Survey Report: Sydney 2012/13}},
url = {http://www.bts.nsw.gov.au/ArticleDocuments/79/r2014-11-hts-summary-report\_12-13.pdf.aspx},
year = {2014}
}
@article{Kitchin2013,
author = {Kitchin, R.},
doi = {10.1177/2043820613513388},
file = {:media/robin/data/Copy/1Lit/2013/Kitchin - 2013 - Big data and human geography Opportunities, challenges and risks.pdf:pdf},
isbn = {2043820613},
issn = {2043-8206},
journal = {Dialogues in Human Geography},
keywords = {and practices,big data,data deluge,human geography,like many terms used,methodology,praxis,rapidly evol-,theory,there is no,to refer to the,ving use of technologies},
month = dec,
number = {3},
pages = {262--267},
title = {{Big data and human geography: Opportunities, challenges and risks}},
url = {http://dhg.sagepub.com/lookup/doi/10.1177/2043820613513388},
volume = {3},
year = {2013}
}
@article{Gaffron2003,
author = {Gaffron, P},
doi = {10.1016/S0967-070X(03)00024-6},
file = {:media/robin/data/Copy/1Lit/2003/Gaffron - 2003 - The implementation of walking and cycling policies in British local authorities.pdf:pdf},
issn = {0967070X},
journal = {Transport Policy},
keywords = {british local authorities,implementation,national cycling strategy,walking and cycling policies},
month = jul,
number = {3},
pages = {235--244},
title = {{The implementation of walking and cycling policies in British local authorities}},
url = {http://linkinghub.elsevier.com/retrieve/pii/S0967070X03000246},
volume = {10},
year = {2003}
}
@article{Rae2009,
author = {Rae, Alasdair},
doi = {10.1016/j.compenvurbsys.2009.01.007},
file = {:media/robin/data/Copy/1Lit/2009/Rae - 2009 - From spatial interaction data to spatial interaction information Geovisualisation and spatial structures of migration from.pdf:pdf},
isbn = {0198-9715},
issn = {01989715},
journal = {Computers, Environment and Urban Systems},
keywords = {Flow mapping,Folder - GraphVisualization,GIS,Geovisualisation,Migration,Spatial interaction data,Urska supplied paper,cartography,demography,flow,jtc,movement,network-analysis,social network,spatial,spatial interaction data,spatial-networks,visualization},
mendeley-tags = {Flow mapping,Folder - GraphVisualization,GIS,Geovisualisation,Migration,Spatial interaction data,Urska supplied paper,cartography,demography,flow,jtc,movement,network-analysis,social network,spatial,spatial-networks,visualization},
month = may,
number = {3},
pages = {161--178},
publisher = {Elsevier Ltd},
title = {{From spatial interaction data to spatial interaction information? Geovisualisation and spatial structures of migration from the 2001 UK census}},
url = {http://linkinghub.elsevier.com/retrieve/pii/S019897150900009X},
volume = {33},
year = {2009}
}

license: MIT

repository: Robinlovelace/pct

repo_name: Robinlovelace/pct

gha_language: TeX

extension: bib


text:
@inproceedings{machiry2017boomerang,
  title={BOOMERANG: Exploiting the Semantic Gap in Trusted Execution Environments},
  author={Machiry, Aravind and Gustafson, Eric and Spensky, Chad and Salls, Christopher and Stephens, Nick and Wang, Ruoyu and Bianchi, Antonio and Choe, Yung Ryn and Kruegel, Christopher and Vigna, Giovanni},
  booktitle={Proceedings of the Network and Distributed System Security Symposium},
  year={2017}
}

gha_license_id: MIT