public void AddressSpaceContextNotExistingFileNameTestMethod()
 {
     IAddressSpaceContext _as = new AddressSpaceContext(x => { });
       Assert.IsNotNull(_as);
       FileInfo _fi = new FileInfo("NotExistingFileName.xml");
       _as.ImportUANodeSet(_fi);
 }
예제 #2
0
 public void CreateUAModelContext()
 {
     UANodeSet _tm = TestData.CreateNodeSetModel();
       AddressSpaceContext _as = new AddressSpaceContext(x => { });
       UAModelContext _mc = new UAModelContext(_tm.Aliases, _tm.NamespaceUris, _as);
       Assert.IsNotNull(_mc);
 }
 public void AddressSpaceContextImportUANodeSetNullTestMethod2()
 {
     IAddressSpaceContext _as = new AddressSpaceContext(x => { });
       Assert.IsNotNull(_as);
       FileInfo _fi = null;
       _as.ImportUANodeSet(_fi);
 }
 public void AddressSpaceContextImportUANodeSetNullTestMethod1()
 {
     IAddressSpaceContext _as = new AddressSpaceContext(x => { });
       Assert.IsNotNull(_as);
       UANodeSet _ns = null;
       _as.ImportUANodeSet(_ns);
 }
        public void DuplicatedNodeIdTestMethod()
        {
            FileInfo _testDataFileInfo = new FileInfo(@"ModelsWithErrors\DuplicatedNodeId.xml");

            Assert.IsTrue(_testDataFileInfo.Exists);
            List <TraceMessage> _trace = new List <TraceMessage>();
            int _diagnosticCounter     = 0;
            IAddressSpaceContext _as   = new AddressSpaceContext(z => TraceDiagnostic(z, _trace, ref _diagnosticCounter));

            Assert.IsNotNull(_as);
            _as.ImportUANodeSet(_testDataFileInfo);
            Assert.AreEqual <int>(1, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            _as.ValidateAndExportModel(m_NameSpace);
            Assert.AreEqual <int>(1, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            Assert.IsTrue(_trace.Where <TraceMessage>(x => x.BuildError.Identifier == "P3-0502020000").Any <TraceMessage>());
        }
        private List <UANodeContext> ValidationUnitTest(FileInfo _testDataFileInfo, int nodes)
        {
            List <TraceMessage> _trace = new List <TraceMessage>();
            int _diagnosticCounter     = 0;
            IAddressSpaceContext _as   = new AddressSpaceContext(z => TraceDiagnostic(z, _trace, ref _diagnosticCounter));

            Assert.IsNotNull(_as);
            Assert.AreEqual <int>(0, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            _as.ImportUANodeSet(_testDataFileInfo);
            Assert.AreEqual <int>(0, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            List <UANodeContext> _nodes = ((AddressSpaceContext)_as).UTValidateAndExportModel(1);

            Assert.AreEqual <int>(nodes, ((AddressSpaceContext)_as).UTValidateAndExportModel(1).Count);
            _as.ValidateAndExportModel();
            Assert.AreEqual <int>(0, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            return(_nodes);
        }
        public void UndefinedHasTypeDefinitionTestMethod()
        {
            FileInfo _testDataFileInfo = new FileInfo(@"ModelsWithErrors\UndefinedHasTypeDefinition.xml");

            Assert.IsTrue(_testDataFileInfo.Exists);
            List <TraceMessage> _trace = new List <TraceMessage>();
            int _diagnosticCounter     = 0;
            IAddressSpaceContext _as   = new AddressSpaceContext(z => TraceDiagnostic(z, _trace, ref _diagnosticCounter));

            Assert.IsNotNull(_as);
            _as.ImportUANodeSet(_testDataFileInfo);
            Assert.AreEqual <int>(0, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            _as.ValidateAndExportModel(m_NameSpace);
            //TODO Recognize problems with P3.7.13 HasTypeDefinition ReferenceType #39
            Assert.Inconclusive("Instances are not imported - the error is not recognized.");
            Assert.AreEqual <int>(1, _trace.Where <TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count <TraceMessage>());
            Assert.AreEqual <int>(1, _trace.Where <TraceMessage>(x => x.BuildError.Identifier == "P3-0713000000").Count <TraceMessage>());
        }
예제 #8
0
        private List <IUANodeContext> ValidateAndExportModelUnitTest(FileInfo testDataFileInfo, int numberOfNodes)
        {
            List <TraceMessage>  _trace = new List <TraceMessage>();
            IAddressSpaceContext _as    = new AddressSpaceContext(z => TraceDiagnostic(z, _trace));

            Assert.AreEqual <int>(0, _trace.Count);
            _as.ImportUANodeSet(testDataFileInfo);
            Assert.AreEqual <int>(0, _trace.Count);
            ((AddressSpaceContext)_as).UTAddressSpaceCheckConsistency(x => { Assert.Fail(); });
            ((AddressSpaceContext)_as).UTReferencesCheckConsistency((x, y, z, v) => Assert.Fail());
            IEnumerable <IUANodeContext> _nodes = null;

            ((AddressSpaceContext)_as).UTValidateAndExportModel(1, x => _nodes = x);
            Assert.AreEqual <int>(numberOfNodes, _nodes.Count <IUANodeContext>());
            _as.ValidateAndExportModel();
            Assert.AreEqual <int>(0, _trace.Count);
            return(_nodes.ToList <IUANodeContext>());
        }
        private NvInternalResult UnmapBuffer(ref UnmapBufferArguments arguments)
        {
            AddressSpaceContext addressSpaceContext = GetAddressSpaceContext(Context);

            lock (addressSpaceContext)
            {
                if (addressSpaceContext.RemoveMap(arguments.Offset, out long size))
                {
                    if (size != 0)
                    {
                        addressSpaceContext.Gmm.Free((ulong)arguments.Offset, (ulong)size);
                    }
                }
                else
                {
                    Logger.PrintWarning(LogClass.ServiceNv, $"Invalid buffer offset {arguments.Offset:x16}!");
                }
            }

            return(NvInternalResult.Success);
        }
예제 #10
0
        private NvInternalResult UnmapBuffer(ref UnmapBufferArguments arguments)
        {
            AddressSpaceContext addressSpaceContext = GetAddressSpaceContext(Context);

            lock (addressSpaceContext)
            {
                if (addressSpaceContext.RemoveMap(arguments.Offset, out ulong size))
                {
                    if (size != 0)
                    {
                        _memoryAllocator.DeallocateRange(arguments.Offset, size);
                        addressSpaceContext.Gmm.Unmap(arguments.Offset, size);
                    }
                }
                else
                {
                    Logger.Warning?.Print(LogClass.ServiceNv, $"Invalid buffer offset {arguments.Offset:x16}!");
                }
            }

            return(NvInternalResult.Success);
        }
예제 #11
0
        private static void Do(Options options)
        {
            PrintLogo(options);
            Action <TraceMessage> _tracingMethod = z => Console.WriteLine(z.ToString());
            IAddressSpaceContext  _as            = new AddressSpaceContext(_tracingMethod);
            ModelDesignExport     _exporter      = new ModelDesignExport();
            bool _exportModel = false;

            if (!string.IsNullOrEmpty(options.ModelDesignFileName))
            {
                _as.InformationModelFactory = _exporter.GetFactory(options.ModelDesignFileName, _tracingMethod);
                _exportModel = true;
            }
            if (options.Filenames == null)
            {
                throw new ArgumentOutOfRangeException($"{nameof(options.Filenames)}", "List of input files to convert i incorrect. At least one file UANodeSet must be entered.");
            }
            foreach (string _path in options.Filenames)
            {
                FileInfo _fileToRead = new FileInfo(_path);
                if (!_fileToRead.Exists)
                {
                    throw new FileNotFoundException(string.Format($"FileNotFoundException - the file {_path} doesn't exist.", _fileToRead.FullName));
                }
                _as.ImportUANodeSet(_fileToRead);
            }
            if (string.IsNullOrEmpty(options.IMNamespace))
            {
                _as.ValidateAndExportModel();
            }
            else
            {
                _as.ValidateAndExportModel(options.IMNamespace);
            }
            if (_exportModel)
            {
                _exporter.ExportToXMLFile(options.Stylesheet);
            }
        }
        private NvInternalResult AllocSpace(ref AllocSpaceArguments arguments)
        {
            AddressSpaceContext addressSpaceContext = GetAddressSpaceContext(Context);

            ulong size = (ulong)arguments.Pages * (ulong)arguments.PageSize;

            NvInternalResult result = NvInternalResult.Success;

            lock (addressSpaceContext)
            {
                // Note: When the fixed offset flag is not set,
                // the Offset field holds the alignment size instead.
                if ((arguments.Flags & AddressSpaceFlags.FixedOffset) != 0)
                {
                    arguments.Offset = (long)addressSpaceContext.Gmm.ReserveFixed((ulong)arguments.Offset, size);
                }
                else
                {
                    arguments.Offset = (long)addressSpaceContext.Gmm.Reserve((ulong)size, (ulong)arguments.Offset);
                }

                if (arguments.Offset < 0)
                {
                    arguments.Offset = 0;

                    Logger.PrintWarning(LogClass.ServiceNv, $"Failed to allocate size {size:x16}!");

                    result = NvInternalResult.OutOfMemory;
                }
                else
                {
                    addressSpaceContext.AddReservation(arguments.Offset, (long)size);
                }
            }

            return(result);
        }
예제 #13
0
 public void CreateUAModelContextNodeAliasNull()
 {
     UANodeSet _tm = TestData.CreateNodeSetModel();
       AddressSpaceContext _as = new AddressSpaceContext(x => { });
       UAModelContext _mc = new UAModelContext(null, _tm.NamespaceUris, _as);
 }
 public void AddressSpaceContextCreatorTestMethod()
 {
     AddressSpaceContext _as = new AddressSpaceContext(x => { });
       Assert.IsNotNull(_as);
       Assert.IsNotNull(_as.UTTryGetUANodeContext(VariableTypes.PropertyType));
 }
 public AddressSpaceWrapper()
 {
     AddressSpaceContext = new AddressSpaceContext(x => { Helpers.TraceHelper.TraceDiagnostic(x, _trace, ref _diagnosticCounter); });
 }
예제 #16
0
        private NvInternalResult MapBufferEx(ref MapBufferExArguments arguments)
        {
            const string mapErrorMsg = "Failed to map fixed buffer with offset 0x{0:x16} and size 0x{1:x16}!";

            AddressSpaceContext addressSpaceContext = GetAddressSpaceContext(Owner);

            NvMapHandle map = NvMapDeviceFile.GetMapFromHandle(Owner, arguments.NvMapHandle, true);

            if (map == null)
            {
                Logger.PrintWarning(LogClass.ServiceNv, $"Invalid NvMap handle 0x{arguments.NvMapHandle:x8}!");

                return(NvInternalResult.InvalidInput);
            }

            long physicalAddress;

            if ((arguments.Flags & AddressSpaceFlags.RemapSubRange) != 0)
            {
                lock (addressSpaceContext)
                {
                    if (addressSpaceContext.TryGetMapPhysicalAddress(arguments.Offset, out physicalAddress))
                    {
                        long virtualAddress = arguments.Offset + arguments.BufferOffset;

                        physicalAddress += arguments.BufferOffset;

                        if (addressSpaceContext.Vmm.Map(physicalAddress, virtualAddress, arguments.MappingSize) < 0)
                        {
                            string message = string.Format(mapErrorMsg, virtualAddress, arguments.MappingSize);

                            Logger.PrintWarning(LogClass.ServiceNv, message);

                            return(NvInternalResult.InvalidInput);
                        }

                        return(NvInternalResult.Success);
                    }
                    else
                    {
                        Logger.PrintWarning(LogClass.ServiceNv, $"Address 0x{arguments.Offset:x16} not mapped!");

                        return(NvInternalResult.InvalidInput);
                    }
                }
            }

            physicalAddress = map.Address + arguments.BufferOffset;

            long size = arguments.MappingSize;

            if (size == 0)
            {
                size = (uint)map.Size;
            }

            NvInternalResult result = NvInternalResult.Success;

            lock (addressSpaceContext)
            {
                // Note: When the fixed offset flag is not set,
                // the Offset field holds the alignment size instead.
                bool virtualAddressAllocated = (arguments.Flags & AddressSpaceFlags.FixedOffset) == 0;

                if (!virtualAddressAllocated)
                {
                    if (addressSpaceContext.ValidateFixedBuffer(arguments.Offset, size))
                    {
                        arguments.Offset = addressSpaceContext.Vmm.Map(physicalAddress, arguments.Offset, size);
                    }
                    else
                    {
                        string message = string.Format(mapErrorMsg, arguments.Offset, size);

                        Logger.PrintWarning(LogClass.ServiceNv, message);

                        result = NvInternalResult.InvalidInput;
                    }
                }
                else
                {
                    arguments.Offset = addressSpaceContext.Vmm.Map(physicalAddress, size);
                }

                if (arguments.Offset < 0)
                {
                    arguments.Offset = 0;

                    Logger.PrintWarning(LogClass.ServiceNv, $"Failed to map size 0x{size:x16}!");

                    result = NvInternalResult.InvalidInput;
                }
                else
                {
                    addressSpaceContext.AddMap(arguments.Offset, size, physicalAddress, virtualAddressAllocated);
                }
            }

            return(result);
        }
 public void CreateUAModelContextModelNamespaceUrisNull()
 {
     UANodeSet           _tm = TestData.CreateNodeSetModel();
     AddressSpaceContext _as = new AddressSpaceContext(x => { });
     UAModelContext      _mc = new UAModelContext(_tm.Aliases, null, _as);
 }
 //Helpers
 private static void ValidateAndExportModelPreparation(out UANodeSet _ns, out IAddressSpaceContext _as)
 {
     _ns = TestData.CreateNodeSetModel();
       List<TraceMessage> _trace = new List<TraceMessage>();
       int _diagnosticCounter = 0;
       Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
       Assert.IsTrue(_ns.NamespaceUris.Length >= 1, "Wrong test data - NamespaceUris must contain more then 2 items");
       _as = new AddressSpaceContext(x => { Helpers.TraceHelper.TraceDiagnostic(x, _trace, ref _diagnosticCounter); });
       Assert.IsNotNull(_as);
       Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
       _as.ImportUANodeSet(_ns);
       Assert.AreEqual<int>(0, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
 }
예제 #19
0
        private NvInternalResult MapBufferEx(ref MapBufferExArguments arguments)
        {
            const string mapErrorMsg = "Failed to map fixed buffer with offset 0x{0:x16}, size 0x{1:x16} and alignment 0x{2:x16}!";

            AddressSpaceContext addressSpaceContext = GetAddressSpaceContext(Context);

            ulong physicalAddress;

            if ((arguments.Flags & AddressSpaceFlags.RemapSubRange) != 0)
            {
                lock (addressSpaceContext)
                {
                    if (addressSpaceContext.TryGetMapPhysicalAddress(arguments.Offset, out physicalAddress))
                    {
                        ulong virtualAddress = arguments.Offset + arguments.BufferOffset;

                        physicalAddress += arguments.BufferOffset;
                        addressSpaceContext.Gmm.Map(physicalAddress, virtualAddress, arguments.MappingSize);

                        return(NvInternalResult.Success);
                    }
                    else
                    {
                        Logger.Warning?.Print(LogClass.ServiceNv, $"Address 0x{arguments.Offset:x16} not mapped!");

                        return(NvInternalResult.InvalidInput);
                    }
                }
            }

            NvMapHandle map = NvMapDeviceFile.GetMapFromHandle(Owner, arguments.NvMapHandle);

            if (map == null)
            {
                Logger.Warning?.Print(LogClass.ServiceNv, $"Invalid NvMap handle 0x{arguments.NvMapHandle:x8}!");

                return(NvInternalResult.InvalidInput);
            }

            ulong pageSize = (ulong)arguments.PageSize;

            if (pageSize == 0)
            {
                pageSize = (ulong)map.Align;
            }

            physicalAddress = map.Address + arguments.BufferOffset;

            ulong size = arguments.MappingSize;

            if (size == 0)
            {
                size = (uint)map.Size;
            }

            NvInternalResult result = NvInternalResult.Success;

            lock (addressSpaceContext)
            {
                // Note: When the fixed offset flag is not set,
                // the Offset field holds the alignment size instead.
                bool virtualAddressAllocated = (arguments.Flags & AddressSpaceFlags.FixedOffset) == 0;

                if (!virtualAddressAllocated)
                {
                    if (addressSpaceContext.ValidateFixedBuffer(arguments.Offset, size, pageSize))
                    {
                        addressSpaceContext.Gmm.Map(physicalAddress, arguments.Offset, size);
                    }
                    else
                    {
                        string message = string.Format(mapErrorMsg, arguments.Offset, size, pageSize);

                        Logger.Warning?.Print(LogClass.ServiceNv, message);

                        result = NvInternalResult.InvalidInput;
                    }
                }
                else
                {
                    ulong va = _memoryAllocator.GetFreeAddress(size, out ulong freeAddressStartPosition, pageSize);
                    if (va != NvMemoryAllocator.PteUnmapped)
                    {
                        _memoryAllocator.AllocateRange(va, size, freeAddressStartPosition);
                    }

                    addressSpaceContext.Gmm.Map(physicalAddress, va, size);
                    arguments.Offset = va;
                }

                if (arguments.Offset == NvMemoryAllocator.PteUnmapped)
                {
                    arguments.Offset = 0;

                    Logger.Warning?.Print(LogClass.ServiceNv, $"Failed to map size 0x{size:x16}!");

                    result = NvInternalResult.InvalidInput;
                }
                else
                {
                    addressSpaceContext.AddMap(arguments.Offset, size, physicalAddress, virtualAddressAllocated);
                }
            }

            return(result);
        }
예제 #20
0
 public NvHostAsGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, long owner) : base(context, owner)
 {
     _asContext       = new AddressSpaceContext(context.Device.Gpu.CreateMemoryManager(owner));
     _memoryAllocator = new NvMemoryAllocator();
 }