diff --git a/pkg/nvml/api.go b/pkg/nvml/api.go index fdf27bd..6ab590d 100644 --- a/pkg/nvml/api.go +++ b/pkg/nvml/api.go @@ -25,6 +25,7 @@ package nvml //go:generate moq -out mock/extendedinterface.go -pkg mock . ExtendedInterface:ExtendedInterface type ExtendedInterface interface { LookupSymbol(string) error + GetErrors() []error } // libraryOptions hold the paramaters than can be set by a LibraryOption diff --git a/pkg/nvml/lib.go b/pkg/nvml/lib.go index bc4c3de..e1c7f42 100644 --- a/pkg/nvml/lib.go +++ b/pkg/nvml/lib.go @@ -51,6 +51,8 @@ type library struct { path string refcount refcount dl dynamicLibrary + + errors []error } var _ Interface = (*library)(nil) @@ -98,13 +100,21 @@ func (l *library) LookupSymbol(name string) error { return l.dl.Lookup(name) } +// GetErrors returns errors that are associated with the library but not NVML. +func (l *library) GetErrors() []error { + return l.errors +} + // load initializes the library and updates the versioned symbols. // Multiple calls to an already loaded library will return without error. func (l *library) load() (rerr error) { l.Lock() defer l.Unlock() - defer func() { l.refcount.IncOnNoError(rerr) }() + defer func() { + l.errors = append(l.errors, rerr) + l.refcount.IncOnNoError(rerr) + }() if l.refcount > 0 { return nil } @@ -129,7 +139,10 @@ func (l *library) close() (rerr error) { l.Lock() defer l.Unlock() - defer func() { l.refcount.DecOnNoError(rerr) }() + defer func() { + l.errors = append(l.errors, rerr) + l.refcount.DecOnNoError(rerr) + }() if l.refcount != 1 { return nil }